Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re: Reloading modules- suppressing warnings works sometimes? by tachyon
in thread Reloading modules- suppressing warnings works sometimes? by JPaul

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2023-12-06 12:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (30 votes). Check out past polls.

    Notices?