[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: #!/Perl question

On  3 Sep, Hans van den Boogert wrote:
> I'm trying to learn some Perl. I found an on-line book which is Unix
> biased, but the scripts all start with #!/usr/local/bin/perl (which makes
> sense if you have compiled and installed it yourself). However, on my
> Debian system Perl was of course put in /usr/bin/perl. So how can I write a
> Perl script that be executed on a variety of systems (Unix/Linux/DOS)?? 
> -- a somebody who last programmed in BASIC back in '84. (Please don't
> laugh. I was young and my teacher made me to).

One can usually be reasonably sure (at least more certain than of the
location of the perl executable...) that /bin/sh exists... That is if
you're on a Unix system (yes, I count Linux as Unix,tho it ain't 
Unix (tm) (if it walks like a duck etc...))

Use this incantation at the top of your files instead (will start the
file as a sh-script that starts perl (as found by the PATH-variable) on
the file itself...

#! -*-perl-*-
eval 'exec perl -x -S $0 ${1:"$@"}'
  if 0;

To automatically start start perl scripts on a WinDOS machine you
usually connect the file suffix you use (.pl) with the Perl interpreter
(dunno exactly how) AFAIK there's no support for the hashbang line. You
can also run a little script on your perl scripts that transforms them
into a .bat (IIRC) file that can be run from anywhere. Will be
interesting to see what happens with Windows new scripting host (if
that was what it was called (teflon coated memory...:-)) 
On a pure DOS system? I have no idea... Could probably do the
conversion to .bat routine described above...
On a Mac you save the scripts as either a droplet or a freestanding exe
(big) from the MacPerl application (supports the hashbang line as far
as it reads the switches set there)


|                  Linux: Turn on...Tune in...Fork out...                 |
| Michael Tempsch, member of Ballistic Wizards, TIP#088, POG#130, PPIG#11 |
|         d1temp@[dtek.chalmers.se|hotmail.com] tempsch@telia.com         |
|  Cell.Phone:+46 705487554   URL:http://www.dtek.chalmers.se/%7Ed1temp   |

Reply to: