Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Don't ask to ask, just ask
 
PerlMonks  

Re^3: scope of "use strict"? (needed: "superstrict")

by argv (Pilgrim)
on Jul 07, 2005 at 01:14 UTC ( [id://473031]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re^2: scope of "use strict"? (needed: "superstrict")
in thread scope of "use strict"? (needed: "superstrict")

Using -w on the command line will turn on warning for the script AND for modules (unless they explicitely turn them off).

Geez--call me stupid... but this doesn't seem to do it for me. I've got a simple perl module Foo.pm that exports a single function, foobar()

Package Foo; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw($foo foobar); $foo = "bar"; sub foobar { $blah = "hi"; print "$foo $blah\n"; } 1;

I wrote a perl script (foo.pl) that imports Foo.pm:

#!/usr/bin/perl use Foo qw(foobar); $bar = "hi"; foobar();

I inserted stuff in both the .pl and the .pm files that should generate warnings to test this. (Running foo.pl with no warnings is clean, expectedly.) So, I run:

perl -w foo.pl

and sure enough, I get a warning in my foo.pl script, but I do not get a warning for the $blah = "hi"; line in Foo.pm. If I add "use warnings;" to the top of Foo.pm as well, then yes, I do get a warning for Foo.pm. But, this goes against what you said: that "perl -w" should propagate the warnings to all the modules... what am I missing?

dan

ps. On another note entirely, "use strict;" in the module complains about $bar, which is exported. This is how the doc says to do it, and I see no other resource that says differently.

Replies are listed 'Best First'.
Re^4: scope of "use strict"? (needed: "superstrict")
by rev_1318 (Chaplain) on Jul 07, 2005 at 02:35 UTC
    Why would you expect a warning from $blah = "hi";? There is nothing wrong with your package (except the Package statement, which should read package). The only warning you should get (and do get with warnings turned on) is:

    Name "main::bar" used only once: possible typo...

    which is correct.

    Paul

Re^4: scope of "use strict"? (needed: "superstrict")
by ikegami (Patriarch) on Jul 12, 2005 at 13:49 UTC

    (Sorry for not getting to you sooner; I was on vacation.)

    Your module doesn't give warnings because there's nothing to warn. Even if you added use warnings to the module, there still wouldn't be any warnings. Here's an example of -w affecting modules:

    >type Foo.pm package Foo; sub foobar { print undef; } 1; >type foo.pl use Foo; Foo::foobar(); >perl -w foo.pl Use of uninitialized value in print at Foo.pm line 4.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://473031]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.