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

I concur with the "eval use".

I have an application which currently uses this system and it works perfectly. You may want to check $@ for problems during the execution of the eval, but otherwise all is well.

In my usage, this technique allows me to include OS-specific modules and code while leaving the main application oblivious to the OS-specific differences. I am basically using $^O ($OSNAME) to decide what modules to load with "eval use".

The application in question is a custom build system. I have a function that is called "build_installer" that is really implemented 5 different ways on different platforms, all without any sort of if blocks. I simply implemented the function 5 different times in 5 different modules and pick the right one at runtime based on the OS the user is running. This way, the Win32 version can use Win32 modules without caring about not being able to run those under Linux, etc.

Replies are listed 'Best First'.
Re: Re: Re: Load all modules in directory
by Anonymous Monk on Dec 11, 2003 at 16:11 UTC
    Don't do that. String eval is inefficient. You get the same results with eval { require $modname; $modname->import(); };