Click to See Complete Forum and Search --> : Different perl locations on different servers.


jakeiii
11-02-2007, 06:01 AM
I'm trying to learn the best way to manage having different perl locations on different servers. I like to test my CGI Perl scripts on my own laptop, work computer and actual site, but they all have different locations for perl. Currently, I deal with this by adding the following to the beginning of each perl script.


#! /bin/sh
if [ `uname -n` = "-- computer name --" ]
then
eval ' exec /sw/perl/5.6.1/WS/7/bin/perl -x $0 "$@" '
else
eval ' exec /usr/bin/perl -x $0 "$@" '
fi
#! perl


Is there a better way to deal with this? Perhaps within perl rather than relying on /bin/sh ?

TIA
Jake

Sixtease
11-09-2007, 08:31 PM
I see several ways to do it:

You can use #!/usr/bin/env perl as the Shebang line and the env program will determine where your perl executable is and run it for you. Honestly, I don't know if this imposes a security threat but I think it does not.


If you're just testing on the other computers and have root access there, maybe I'd add symlink to perl in the server's location.
If /sw/perl/5.6.1/WS/7/bin/ is the path to perl on the server, then I'd do mkdir -p /sw/perl/5.6.1/WS/7/bin; ln -s `which perl` /sw/perl/5.6.1/WS/7/bin/perl on the local machine. That would make the server shebang work there too.


You can run perl explicitly from command line on the testing machines: You'd not do ./myscript.pl but perl myscript.pl

Since perl isn't invoked if the shebang line doesn't point to it, there can't be a way to do it "from perl". I find your encapsulation method quite clever but I wonder how much of a performance penalty you pay for executing shell on every page hit...

If you figure out a better solution, please post it here. I'd be very interested.