This is interesting!

If you're importing subs, you must also replace them in the importing package. It's best to call import() on the reloaded package specifically. Observe:

use QStat; foo(); print "QStat foo is: ", \&QStat::foo, "\n"; print "Imported foo is: ", \&main::foo, "\n"; <STDIN>; my $loc = $INC{QStat}; delete $INC{QStat}; require $loc; # slightly more difficult # QStat->import(); print "After import, foo is: ", \&main::foo, "\n"; print "And in the package it is: ", \&QStat::foo, "\n";
Try it with and without the import(), and you'll see what's going on. *foo in the main package and *foo in QStat will point to different CVs, and that's the problem. (The STDIN part is in there so I could change what foo() does while the program is running.)

I wonder if it would be worth writing a 'reimport' module...


In reply to Re: Re: Re: Reloading Modules by chromatic
in thread Reloading Modules by rendler

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.