in reply to Re: Load all modules in directory
in thread Load all modules in directory

Hmm...I tried the above without success. It looks like the problem is that the functions in the Module are not being pulled into the current package

. The require and import proceed without failure, but as soon as the function is called, I get
Undefined subroutine &main::webcast_header called at multi_reporter.pl + line 133
. Here is the current non-working thing that I'm trying:
BEGIN { $mod_path="/home/tboyd/lib/site_perl/5.6.1/Tools/"; unshift @INC, $mod_path; my @mods = glob("$mod_path/*"); for (@mods) { s/.*\/(\w+\.pm)$/$1/gi; require $_; $_->import; } }
The module that is being called works just fine under a "use" directive. Why might the import not be working? -C P.S. removing the .pm will make this thing barf on the "require".

Replies are listed 'Best First'.
Re: Re: Re: Load all modules in directory
by ysth (Canon) on Dec 11, 2003 at 05:13 UTC
    The require needs a file name and the import needs a package name. So you need to figure out how to require "/home/tboyd/lib/site_perl/5.6.1/Tools/ModuleA.pm" but import "Tools::ModuleA".

    You might want to see the thread about import.pm on perl5-porters for ideas about doing this or reasons not to.