home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!wupost!csus.edu!netcom.com!jfh
- From: jfh@netcom.com (Jack Hamilton)
- Subject: Re: How to run a Perl under DOS?
- Message-ID: <1993Jan8.071450.7631@netcom.com>
- Organization: Netcom - Online Communication Services (408 241-9760 guest)
- References: <1993Jan6.211929.169@kocrsv01.delcoelect.com> <1993Jan7.182209.1931@unipalm.co.uk> <1268@alsys1.aecom.yu.edu>
- Date: Fri, 8 Jan 1993 07:14:50 GMT
- Lines: 62
-
- In article <1268@alsys1.aecom.yu.edu> manaster@yu1.yu.edu (Chaim Manaster) asks how the foillowing script works:
-
- 1 >> @rem = '
- 2 >> some dos batch commands
- 3 >> PERL -S %0.BAT %1 %2 %3 (etc)
- 4 >> GOTO ENDOFPERL
- 5 >> ';
- 6 >> # your perl script here
- 7 >> __END__
- 8 >> :ENDOFPERL
- 9 >> some more DOS if you need it
- 10 >> rem Drop through end of Batch file
-
-
- I added line numbers to the left to make it easier to explain.
-
- (1) is a valid statement in both perl and DOS batch. In perl, it starts an
- assignment statement which is finished in (5); in DOS, it's an unechoed
- remark command.
-
- (2), which can be several lines, is just DOS commands. When the file is
- executed as a perl script, these commands are ignored, because they're
- imbedded inside the string started in (1). When the file is executed as a
- batch file, they're executed (DOS doesn't know about continuations), so you
- can use them for setup or whatever.
-
- (3), like (2), is ignored in perl, but calls the perl interpreter in batch.
- The -S options means "search the path for the script". The "%0" expands to
- the name of the file. The remaining things are just parameters to be
- passed to perl.
-
- (4) is ignored in perl, but in DOS it's a GOTO command pointing to (8).
- The contents of (5)-(7) are perl commands, and probably won't be valid DOS
- commands. The GOTO just skips over them.
-
- (5) is skipped over when the file is executed as batch, but ends the
- assignment statement started in (1) when executed as a perl script.
-
- (6) is any number of perl statements.
-
- (7) is a special perl statement. It indicates that the end of the program
- has been reached. Perl will not treat anything after this line as a
- program statement. This example didn't show it, but you could put data
- lines after (7), and read them from your perl program using the filehandle
- DATA.
-
- Note that __END__ has a total of 4 underscores.
-
- (8) is interpreted only by DOS. It's a label, and the object of the GOTO
- in (4).
-
- (9) and (10) and just DOS commands.
-
-
- You do something similar using the -x command line option instead of the -S
- command line option.
-
-
- --
-
- -----------------------------------------------------------------------
- Jack Hamilton jfh@netcom.com P. O. Box 281107 SF, CA 94128-1107
-