Perl: Prepend a script before script execution
I need to prepend some code before I run my Perl script. In my prepended script I will set some debug variables and add some debugging subroutines. The easiest way I've found to do this is with the
-M parameters. This allows you to set an include directory, and a specific module to be loaded before your script starts.
I was able to create a
debug.pm in my
/tmp/ directory and prepend it to my Perl script like this:
perl -I/tmp/ -Mdebug my_script.pl
This tells Perl to add
/tmp/ to the list of locations to look for modules, and then to load the module
debug. Then you simply make a
debug.pm that includes the global variables you want to include and your main script will be able to read them.