in reply to How can I source other perl scripts from within a Perl script
eval EXPR
When passed a scalar containing some code, eval evaluates it in the current context. That can be very nice.
Of cource it does this at runtime, so its a little slow(as the code in the scalar is compiled at runtime).
It also traps any errors that might pop up.
do FILE
This is the old way of including files. It basically slurps in the file, and evaluates it. However, the code in the file,
cannot see lexical variables in your program(and I guess that lexicals in the included file is not visible in the main code either)
It does some nifty things though. It searches @INC directories for the file, and as oposed to the next two commands, it compiles the code each time it is include - which is
something you might want if you are using the file for configuration.
require FILE
Same as do, except a file is never loaded/compiled twice, and any errors in the file
will raise an exception(your program is likely to die...)
use module list
This is almost exactly the same as the following code:
Since its inside a BEGIN block, the module is included before your program has started to execute, and so any errors will be caught before you actually start doing anything. Which is neat....BEGIN { require module; import module list; }
|
|---|