Dear Log,
And speaking of require 5;
-- my favorite incantation to make sure that a Perl .pm file (or any other Perl file) isn't being run as a sh file is require 5 || exit;
. Perl will parse this as (require 5) || exit
and since require 5
will always be true (or fatal), it will never run the exit
. But shells will see that as "run the command require 5
and unless that succeeds, exit this script". At least, that seems to work unless you have a program called "require" in your path. I think I've got that right.
My other bit of shell fun is to alias a shell command "use" to
perl -d -e 'BEGIN{eval qq~use $_;1~ || print $@ for(@ARGV)} 1;'
So I can just run "use LWP HTML::TreeBuilder" at a shell prompt and it starts up Perl, uses those libraries, and starts up the debugger prompt.
The .cshrc line for that alias definition is:
alias use "perl -d -e 'BEGIN{eval qq~use "\$"_;1~ || print "\$"@ for(@ARGV)} 1;' \!*"
Kinda reminds me why I hate shells.
If you're in MSWin-land, the autoexec.bat line to use is:
doskey use=perl -d -e "BEGIN{ eval qq~use $$_;1~ || print $$@ foreach (@ARGV)} 1;" $*