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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.