Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Dynamically load all modules from a directory

by ELISHEVA (Prior)
on Oct 01, 2009 at 15:27 UTC ( [id://798674]=note: print w/replies, xml ) Need Help??


in reply to Dynamically load all modules from a directory

use needs a bare word so it isn't suitable for the kind of dynamic loading you want to do. require can be used instead but you must use the file name as is (don't strip the final .pm) like this:

foreach my $mod(@files){ my($filename, $directories, $suffix) = fileparse($mod); # don't do this - we need the actual filename!!! # $filename=~s/\.pm//gx; require $filename; }

There is a nice example in the perl documentation for require as well.

Best, beth

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://798674]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-06-20 19:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.