cadphile has asked for the wisdom of the Perl Monks concerning the following question:
The perl wrapper is a bourne shell script that runs "uname" to determine what architecture one is in, and then does an exec to the binary specific perl in either sparc (Solaris), i386 (Solaris), or linux. Scripts that use this installation, need to have custom shebang ("#!") headers, so that the script will run on any of the platforms. We're using this setup:/net/tools/perl/perl-5.8.8/bin/perl (wrapper) /net/tools/perl/perl-5.8.8/lib/... /net/tools/perl/perl-5.8.8/sparc/bin/perl /net/tools/perl/perl-5.8.8/i386/bin/perl /net/tools/perl/perl-5.8.8/linux/bin/perl
Using this format, our scripts can run without modification on any of our three platforms. There are numerous reasons why we've settled on this setup. Without Linux support, the header is simpler, and can just be as follows (Note the "perl" magic line can be added behind the bourne shell shebang, and the "-x" is not needed.):#!/bin/sh -- # -*- perl -*- eval 'exec /net/tools/perl/perl-5.8.8/bin/perl -xw $0 ${1+"$@"}' if 0;
The Linux bourne shell however doesn't allow arguments, so the "perl" magic string has to be commented as line #2, and then we have to add "-x" so that perl can figure out where it needs to start executing perl correctly. (Read perlrun for more information.) What I'm writing for advice and help with, is that when we try to debug a script with this header, the debugging structure croaks:#!/bin/sh -- # -*- perl -*- eval 'exec /net/tools/perl/perl-5.8.8/bin/perl -w $0 ${1+"$@"}' if 0;
will run just fine. But to debug, we try this:% myscript.pl
This doesn't work. It starts the debugger OK, but then tries to open "-d" as if it's a file. Here's the code:% /net/tools/perl/perl-5.8.8/linux/bin/perl -d myscript.pl
% cat test-debug.pl #!/bin/sh #!-*- perl -*- eval 'exec /net/tools/perl/perl-5.8.8/bin/perl -wx $0 ${1+"$@"}' if 0; print "$^X\n"; print "HI THERE\n"; exit; % /net/tools/perl/perl-5.8.8/bin/perl -d test-debug.pl Loading DB routines from perl5db.pl version 1.28 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. -d: bad option(s)
So, any advice on how to improve this setup?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: multi-platform perl header for linux and solaris
by graff (Chancellor) on Feb 19, 2011 at 02:10 UTC |