How should I write a UNIX/NT portable Perl script?

Fay, Michael mfay@ti.com
Mon Oct 30 18:05:00 GMT 2000


[My apologies if my attempted post of this on 10/26 actually went out;
I didn't see it myself...]

In the  Cygwin/bash environment, is it possible to write a single Perl
script
such that

1. You invoke the script simply by naming it, without saying 'perl ...':
        script
   option: it would be ok if it had to be called via:
        script.pl
   or
        script.plx

2. The script uses the perl.exe that it finds in the $PATH,
   rather than hard-coding it on the first line.  E.g. the following
   preamble inside the script works on UNIX but I'm having trouble making it
   work under bash/cygwin without saying 'perl script ...':

        eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
                          && eval 'exec perl -w -S $0 $argv:q'
                          if 0;

   The classic
        #!/usr/local/bin/perl -w
   is undesirable because I might want to switch perl's easily, e.g. by
   changing $PATH.  Also, this script might run at many sites and
   there are a lot of UNIX system admin's I would have
   to ask to put perl in my favorite place.

3. The mechanism used to accomplish 1. and 2. works identically on UNIX
   and cygwin/Win9x/WinNT.  That is, a single script works in both
   environments.
   -- I don't want to maintain two versions
   -- I don't want to have to write a wrapper every time I write a script
        (but perhaps a single generic wrapper would be ok).

I would be interested to see how others cope with writing Perl scripts
portably.

Michael Fay
Texas Instruments, Santa Barbara
mfay@ti.com

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com



More information about the Cygwin mailing list