in reply to Reloading Modules

Define "didn't work". I created a module called 'QStat.pm', consisting of:
package QStat; BEGIN { print "Compiling QStat!\n"; } sub foo {} 1;
I then turned your subroutine into a standalone script, and added a line to use QStat at the beginning. Under Perl 5.6.1 and 5.7.almost3 I receive:
Compiling QStat! Compiling QStat! Subroutine foo redefined at QStat.pm line 7.
Exactly what I expect. Perhaps you need to print the value of $_ within your loop. Your regexp may not be matching.

Replies are listed 'Best First'.
Re: Re: Reloading Modules
by rendler (Pilgrim) on Feb 03, 2002 at 06:10 UTC
    Yes it does that for me too but when I change something in one of the modules and then make it reload the changes in whatever sub I've changed don't seem to show through.
      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...