use warnings; and use Warnings; give different results

Discussion in 'Perl Misc' started by Ted Sung, Aug 30, 2004.

  1. Ted Sung

    Ted Sung Guest

    D:\perl_scripts>perl -v
    This is perl, v5.6.1 built for MSWin32-x86-multi-thread
    (with 1 registered patch, see perl -V for more detail)

    I have the following simple/trivial script, test.pl:

    use strict;
    use Warnings;
    use Cwd;

    When I run this as perl -w test.pl, I get the following:

    D:\perl_scripts>perl -w test2.pl
    Subroutine bits redefined at d:/perl/lib/warnings.pm line 285.
    Subroutine import redefined at d:/perl/lib/warnings.pm line 304.
    Subroutine unimport redefined at d:/perl/lib/warnings.pm line 314.
    Subroutine __chk redefined at d:/perl/lib/warnings.pm line 325.
    Subroutine enabled redefined at d:/perl/lib/warnings.pm line 373.
    Subroutine warn redefined at d:/perl/lib/warnings.pm line 386.
    Subroutine warnif redefined at d:/perl/lib/warnings.pm line 400.

    Strangely, if I change the upper case 'W' to w so the script is like
    this:

    use strict;
    use warnings;
    use Cwd;

    I don't see these warnings.

    Also, if I remove the 'use Cwd;' line, I don't get any warnings
    regardless of the case of 'W'.

    What is going on here?

    Thanks,

    Ted
     
    Ted Sung, Aug 30, 2004
    #1
    1. Advertisements

  2. Ted Sung wrote:

    > D:\perl_scripts>perl -v
    > This is perl, v5.6.1 built for MSWin32-x86-multi-thread
    > (with 1 registered patch, see perl -V for more detail)
    >
    > I have the following simple/trivial script, test.pl:
    >
    > use strict;
    > use Warnings;
    > use Cwd;
    >
    > When I run this as perl -w test.pl, I get the following:
    >
    > D:\perl_scripts>perl -w test2.pl
    > Subroutine bits redefined at d:/perl/lib/warnings.pm line 285.
    > Subroutine import redefined at d:/perl/lib/warnings.pm line 304.
    > Subroutine unimport redefined at d:/perl/lib/warnings.pm line 314.
    > Subroutine __chk redefined at d:/perl/lib/warnings.pm line 325.
    > Subroutine enabled redefined at d:/perl/lib/warnings.pm line 373.
    > Subroutine warn redefined at d:/perl/lib/warnings.pm line 386.
    > Subroutine warnif redefined at d:/perl/lib/warnings.pm line 400.
    >
    > Strangely, if I change the upper case 'W' to w so the script is like
    > this:
    >
    > use strict;
    > use warnings;
    > use Cwd;
    >
    > I don't see these warnings.
    >
    > Also, if I remove the 'use Cwd;' line, I don't get any warnings
    > regardless of the case of 'W'.
    >
    > What is going on here?


    Case-insensitive file system. The name of the module as given in the
    'use' statement is cached in %INC, so the module only gets parsed once.
    The 'Cwd' module has 'use warnings', and in your second example
    'warnings.pm' isn't loaded again because you've already loaded it.

    In the first example, you (incorrectly) refer to it as Warnings, which
    causes perl to read and parse 'Warnings.pm'. When Cwd's 'use warnings'
    is found, 'warnings.pm' is loaded. But on a case-insensitive file
    system, those are the same file; so you get 'Subroutine ... redefined'
    warnings.

    Avoid the warnings by correctly spelling the name of the module: It's
    'warnings', as in your second example.

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Aug 30, 2004
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Qiangning Hong
    Replies:
    12
    Views:
    931
    Grant Edwards
    Jul 12, 2006
  2. Kerry, Richard
    Replies:
    2
    Views:
    559
    Piet van Oostrum
    Jul 13, 2006
  3. =?Utf-8?B?Ymlj?=
    Replies:
    1
    Views:
    466
    Alexey Smirnov
    May 5, 2007
  4. Alessio

    different results on different compiler

    Alessio, Jul 17, 2009, in forum: C Programming
    Replies:
    6
    Views:
    966
    jameskuyper
    Jul 23, 2009
  5. ks
    Replies:
    9
    Views:
    606
    Jorgen Grahn
    Mar 20, 2010
  6. Sean

    different browser with different results

    Sean, May 18, 2005, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    207
    Chad Z. Hower aka Kudzu
    May 18, 2005
  7. peter pilsl
    Replies:
    2
    Views:
    322
    Shawn Corey
    Sep 28, 2004
  8. HmJ
    Replies:
    0
    Views:
    351
Loading...