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

What about reloading the module? Do I just 'use MyModule qw/foo bar baz/;' again?
  • Comment on Re^2: importing/removing functions from a module into the main namespace

Replies are listed 'Best First'.
Re^3: importing/removing functions from a module into the main namespace
by Joost (Canon) on Mar 14, 2005 at 09:33 UTC
    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 $@; }
      Actually, I just had someone point me to the Module::Reload module which seems to do exactly what I need. Thanks, though.