Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: use Strict: a rigorous way to break my command line variables?

by tilly (Archbishop)
on Aug 09, 2006 at 02:24 UTC ( #566309=note: print w/ replies, xml ) Need Help??


in reply to use Strict: a rigorous way to break my command line variables?

Change use Strict; to use strict;

Short explanation: The name of the module is strict, all lower case. Because Windows is case insensitive, use Strict; will load the module even though it is already loaded. It won't do anything useful with it, but it will load it. Since it was already loaded by something else (or else something else loads it after you did), you get redefinition warnings and no useful effect. Change it to the proper case and you'll have no redefinition warnings, and the module will do something for you.

Long explanation. When you type use Strict; Perl proceeds to do the following:

BEGIN { require Strict; Strict->import(); }
require checks %INC to see whether "Strict.pm" is loaded, and then tries to load it if not. However %INC is case sensitive, so it won't notice that Strict.pm is there if it is looking for strict.pm, and vice versa. Since Windows is case insensitive, if you look for Strict.pm you'll find strict.pm. So Perl decides it doesn't have the module, and tries to load it. Since you're loading the same code twice, you get redefinition errors.

Your bigger problem, though, is that the line Strict->import(); won't do anything useful. You see strict.pm only implements strict::import. So there is no Strict::import to find, and nothing happens.

So make it use strict; and Perl will not try to reload the same module, and (more importantly) Perl will make the method call that turns strict on in your code.


Comment on Re: use Strict: a rigorous way to break my command line variables?
Select or Download Code
Re^2: use Strict: a rigorous way to break my command line variables?
by NamfFohyr (Scribe) on Aug 09, 2006 at 02:31 UTC
    Oh wow. Thanks, tilly, you got it. I'm using MaxOSX though, hurumph;)

    I did type "use Strict" instead of "use strict." When I change it to the lowercase version, everything works again.

    Don't know why I used uppercase. Perhaps it seemed Even Stricter!

    ry

    "I'm not afraid of Al Quaeda. I'm afraid of Al Cracker." -Chris Rock
      When I see people using a case insensitive filesystem, I just assume they are using Windows.

      Bad assumption. Sorry.

      it's funny, on the p5p mailing list today, somebody had filed a bug concerning this *exact* problem; Rafael actually answered by quoting the perl source that was saying that this could not be fixed, that the *previous* fix was bad and had been withdrawn, and the rationale behind it. The truth is that this kind of filesystem **should** be fixed!

Re^2: use Strict: a rigorous way to break my command line variables?
by rodion (Chaplain) on Aug 09, 2006 at 02:36 UTC
    Curiously, this code runs fine when I try it on a Mac (OSX) under perl 5.8.6, when either "use strict;" or "use Strict" is added at the top (with or without "use warnings;" before it).
      I assumed that the OP had not included all of the code necessary to generate the error. Add more code that loads something that loads the other one. Then you'll get the warning.

      Also try use Strict; then try doing something that strict is not supposed to allow. It will be allowed. It should not be.

        Also try use Strict; then try doing something that strict is not supposed to allow. It will be allowed. It should not be.

        Confirmed. As you indicate, while "use Strict;" causes neither a warning nor an error, it does nothing to protect you from the things that "use strict;" does.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://566309]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2014-07-13 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (248 votes), past polls