This is the mail archive of the cygwin@sources.redhat.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

How to write a UNIX/NT portable Perl script


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).

If this isn't achievable, I'll probably give up 1. and use:
        perl script ...

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

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]