in reply to Re^2: importing/removing functions from a module into the main namespace
in thread importing/removing functions from a module into the main namespace

use and require normally only load a module once during execution of the script, even if they're called multiple times. Any imports done by use will be done for each use statement, though.

If you really want to reload a module while running the program, you can do something like this (not 100% foolproof):

use Symbol qw(delete_package); sub re_use { my $module = shift; # "Module::To::Reload" my $fname = $module; $fname =~ s#::#/#g; $fname .= ".pm"; # "Module/To/Reload.pm" delete_package($module); # remove the Module::To::Reload namespace delete $INC{$fname}; # delete the filename from the # "loaded" list eval "use $module" or die $@; }

Replies are listed 'Best First'.
Re^4: importing/removing functions from a module into the main namespace
by agaffney (Beadle) on Mar 14, 2005 at 10:38 UTC
    Actually, I just had someone point me to the Module::Reload module which seems to do exactly what I need. Thanks, though.