in reply to Migrating scripts back to Perl 5.005_03

I thought that '-w' would set $^W globally? I upgraded a few of my modules recently so they pass tests on 5.005_03 and I just left warnings off but had them on (and fatal) during tests. If I put a shebang with -w in my module I won't stomp on the calling script or other modules?

  • Comment on Re: Migrating scripts back to Perl 5.005_03

Replies are listed 'Best First'.
Re: Re: Migrating scripts back to Perl 5.005_03
by ajdelore (Pilgrim) on Sep 05, 2003 at 22:50 UTC

    If I understand perllexwarn, which I am not sure that I do, -w does set $^W globally. (And -W makes it irrevocable). Of course, you can't use the shebang in a module.

    While in 5.6+ you could put use warnings; in a module and have it scoped to that file only, I think that setting $^W would be global unless enclosed in a block, or unless it was somehow contained.

    package foo; use strict; $^W = 1; print "Testing\n", undef; 1; __END__ use strict; use foo; print "Testing\n", undef;

    In the above example, both print statements throw a warning. However, if I do:

    local $^W = 1;

    Then I only get one in the module. Of course, the main thing that perllexwarn seems to say is "don't do any of this stuff." It seems better to take warnings as an all-or-nothing deal in 5.005.

    </ajdelore>

Re: Re: Migrating scripts back to Perl 5.005_03
by fglock (Vicar) on Sep 05, 2003 at 21:20 UTC

    I use #!perl -w only in the test suite.
    This way, users can decide whether to enable warnings or not.

    Update: as I understand from perlrun, a shebang line in a module would not be interpreted at all.