home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / perl / 7717 < prev    next >
Encoding:
Text File  |  1993-01-08  |  2.7 KB  |  73 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!wupost!csus.edu!netcom.com!jfh
  3. From: jfh@netcom.com (Jack Hamilton)
  4. Subject: Re: How to run a Perl under DOS?
  5. Message-ID: <1993Jan8.071450.7631@netcom.com>
  6. Organization: Netcom - Online Communication Services (408 241-9760 guest)
  7. References: <1993Jan6.211929.169@kocrsv01.delcoelect.com> <1993Jan7.182209.1931@unipalm.co.uk> <1268@alsys1.aecom.yu.edu>
  8. Date: Fri, 8 Jan 1993 07:14:50 GMT
  9. Lines: 62
  10.  
  11. In article <1268@alsys1.aecom.yu.edu> manaster@yu1.yu.edu (Chaim Manaster) asks how the foillowing script works: 
  12.  
  13. 1  >>    @rem = '                   
  14. 2  >>    some dos batch commands
  15. 3  >>    PERL -S %0.BAT %1 %2 %3 (etc)
  16. 4  >>    GOTO ENDOFPERL
  17. 5  >>    ';
  18. 6  >>    # your perl script here
  19. 7  >>    __END__
  20. 8  >>    :ENDOFPERL
  21. 9  >>    some more DOS if you need it
  22. 10 >>    rem Drop through end of Batch file
  23.  
  24.  
  25. I added line numbers to the left to make it easier to explain.
  26.  
  27. (1) is a valid statement in both perl and DOS batch.  In perl, it starts an
  28. assignment statement which is finished in (5); in DOS, it's an unechoed
  29. remark command. 
  30.  
  31. (2), which can be several lines, is just DOS commands.  When the file is
  32. executed as a perl script, these commands are ignored, because they're
  33. imbedded inside the string started in (1).  When the file is executed as a
  34. batch file, they're executed (DOS doesn't know about continuations), so you 
  35. can use them for setup or whatever. 
  36.  
  37. (3), like (2), is ignored in perl, but calls the perl interpreter in batch.
  38. The -S options means "search the path for the script".  The "%0" expands to
  39. the name of the file.  The remaining things are just parameters to be
  40. passed to perl. 
  41.  
  42. (4) is ignored in perl, but in DOS it's a GOTO command pointing to (8).
  43. The contents of (5)-(7) are perl commands, and probably won't be valid DOS
  44. commands.  The GOTO just skips over them. 
  45.  
  46. (5) is skipped over when the file is executed as batch, but ends the
  47. assignment statement started in (1) when executed as a perl script. 
  48.  
  49. (6) is any number of perl statements.   
  50.  
  51. (7) is a special perl statement.  It indicates that the end of the program
  52. has been reached.  Perl will not treat anything after this line as a
  53. program statement.  This example didn't show it, but you could put data
  54. lines after (7), and read them from your perl program using the filehandle
  55. DATA. 
  56.  
  57. Note that __END__ has a total of 4 underscores. 
  58.  
  59. (8) is interpreted only by DOS.  It's a label, and the object of the GOTO
  60. in (4).  
  61.  
  62. (9) and (10) and just DOS commands. 
  63.  
  64.  
  65. You do something similar using the -x command line  option instead of the -S
  66. command line option. 
  67.  
  68.  
  69. -- 
  70.  
  71. -----------------------------------------------------------------------
  72. Jack Hamilton   jfh@netcom.com   P. O. Box 281107   SF, CA   94128-1107
  73.