Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Dynamically load all modules from a directory

by ELISHEVA (Prior)
on Oct 01, 2009 at 15:27 UTC ( #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? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2023-04-01 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (77 votes). Check out past polls.

    Notices?