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

Goind point. What might be off service are warnings. Using -w on the command line will turn on warning for the script AND for modules (unless they explicitely turn them off).
  • Comment on Re^2: scope of "use strict"? (needed: "superstrict")

Replies are listed 'Best First'.
Re^3: scope of "use strict"? (needed: "superstrict")
by argv (Pilgrim) on Jul 07, 2005 at 05:14 UTC
    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.

      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

      (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.