http://qs1969.pair.com?node_id=316129


in reply to Reloading modules- suppressing warnings works sometimes?

And, as you'll see soon enough, foo.pm reloads without any complaints, time and time again.

Not on my system it doesn't. The issue is that you effectively have:

{ # one scope no warnings; # but the eval generates an inner scope { # where this over-rides the outer scope no warnings # or $^W = 0 - the inner scope reigns supreme. use warnings; } }

This will remove the warnings from the reload.pm reloading itself but as noted this does not fix bar.

#!/usr/bin/perl use strict; use warnings; use reload; do { print "Hit Enter.\n"; reload::reload("foo"); foo::bar(); reload::reload("reload"); } while <STDIN>; package reload; use warnings; use strict; { no warnings; sub reload { my ($PM) = @_; delete $INC{"$PM.pm"}; eval "require $PM"; } } 1; package foo; use strict; use warnings; sub bar { print "Works\n" } 1; __DATA__ C:\>perl test.pl Hit Enter. Works Hit Enter. Subroutine bar redefined at foo.pm line 4, <STDIN> line 1. Works Hit Enter. Subroutine bar redefined at foo.pm line 4, <STDIN> line 2. Works Hit Enter. Subroutine bar redefined at foo.pm line 4, <STDIN> line 3. Works Hit Enter. Subroutine bar redefined at foo.pm line 4, <STDIN> line 4. Works Hit Enter. Subroutine bar redefined at foo.pm line 4, <STDIN> line 5. Works ^C C:\>

cheers

tachyon

Replies are listed 'Best First'.
Re: Re: Reloading modules- suppressing warnings works sometimes?
by JPaul (Hermit) on Dec 21, 2003 at 19:50 UTC
    Indeed, I messed up the copying in;

    In my local version of foo.pm, I have no 'use warnings;' only 'use strict;' - which, very certainly overrides the 'local $^W = 0;', and gives us the warn.
    (In other words, yea, the notice of bar being redefined is indeed there)

    Oops?
    -- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

Re: Re: Reloading modules- suppressing warnings works sometimes?
by JPaul (Hermit) on Dec 21, 2003 at 05:22 UTC
    Perhaps I made an error copying my working example into PerlMonks - but foo reloads without complaint. Only reload warns.
    I will have to look and see what you're seeing, vs what I'm seeing. Possibly a difference in perl versions, more likely I mucked up the copying in.

    Curious you make one work, and I make the other work, yet the twain do not meet.

    JP,
    -- Alexander Widdlemouse undid his bellybutton and his bum dropped off --