Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

TorgoX (1933)

TorgoX
  sburkeNO@SPAMcpan.org
http://search.cpan.org/~sburke/

"Il est beau comme la retractilité des serres des oiseaux rapaces [...] et surtout, comme la rencontre fortuite sur une table de dissection d'une machine à coudre et d'un parapluie !" -- Lautréamont

Journal of TorgoX (1933)

Monday February 18, 2002
10:48 AM

use

[ #2938 ]
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;" $*

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.