On Sun, 22 Jan 2006 17:39:47 -0800, Tom Phoenix wrote: > On 1/22/06, Ken Perl <[EMAIL PROTECTED]> wrote: > >> May I import all modules located in a directory called >> '/opt/myperlmodules' in Begin block like this? > > What happened when you tried it? > >> $myModules = "/opt/myperlmodules"; >> lib->import($myModules); > > I don't think it will work, but maybe you have a different version of Perl > installed on your machine than I have in my brain. :-)
What perl do you have installed in your brain? Do you have a full CPAN? :-) > Maybe you're doing something quite unusual, but... It's probably not a > defensible programming technique to use whichever modules are found in a > given directory, for much the same reason that recipes seldom suggest > choosing ingredients by location. "Begin with the rightmost box on the > shelf with the breakfast cereal. Next, stir in half of the largest > container on the bottom shelf in the refrigerator. Add a spoonful of every > third spice from the second row of the spice rack...." > > Modules: Ask for them by name. Maybe I'm missing something, but the poster appears to be asking how to achieve the common and useful pattern of plugins, where you control dynamic behavior by deciding what modules are in a particular directory. Of course there's a lot more scaffolding than the poster alluded to, but at some point you do have to load all the modules in a directory. My current favorite way is to eval each file one at a time and extract package directives to push class names onto an array. Ken: that won't work. You need BEGIN blocks, glob(), and a require followed by a $class->import inside the loop. -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>