Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Greetings all;
I have another stoater here, that I'm sure some wise monk will be able to point out what exactly is going on - but truly has me confused.
First of all, I only recently discovered perl could literally reload modules on the fly. This is why I love perl. Not only is this so immensely cool - but perl makes it so easy. I firmly believe this is a sign of a superior language. But enough ass kissing.

My reload module is amply stolen from Apache::StatINC, as suggested here. This works perfectly for loading modules like it should - EXCEPT when it reloads itself. I suspect changing the package namespace on the function while it is running perhaps cocks up the lexical scope for the local - but I'm not entirely positive.

package foo; use strict; use warnings; sub bar { print "Works\n"; } 1; package reload; use strict; use warnings; sub reload { my ($PM) = @_; delete $INC{"$PM.pm"}; local $^W = 0; eval("require $PM;"); } 1; #Script #!/usr/bin/perl -w use strict; use reload; while(<STDIN>) print "Hit Enter.\n"; &reload::reload("foo"); &foo::bar(); &reload::reload("reload"); }
And, as you'll see soon enough, foo.pm reloads without any complaints, time and time again. However reload.pm leaves us with an undesireable "Subroutine redefined" warning.
All I want is for the warning to go away.
I could, simply, not use warnings at all - but I'd much rather find a way around this, if I can. Turning warnings off doesn't work either, I believe also related to scope.

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

Update: Apparently my terminology is guff. Not lexical scope, but dynamic.


In reply to 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 meditating upon the Monastery: (3)
As of 2024-04-26 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found