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

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!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.220106.10383@netcom.com>
  6. Organization: Netcom - Online Communication Services (408 241-9760 guest)
  7. References: <1268@alsys1.aecom.yu.edu> <1993Jan8.071450.7631@netcom.com> <1270@alsys1.aecom.yu.edu>
  8. Date: Fri, 8 Jan 1993 22:01:06 GMT
  9. Lines: 101
  10.  
  11. In article <1270@alsys1.aecom.yu.edu> manaster@yu1.yu.edu (Chaim Manaster) 
  12. writes:
  13. >
  14. >>1  >>    @rem = '                   
  15. >>2  >>    some dos batch commands
  16. >>3  >>    PERL -S %0.BAT %1 %2 %3 (etc)
  17. >>4  >>    GOTO ENDOFPERL
  18. >>5  >>    ';
  19. >>6  >>    # your perl script here
  20. >>7  >>    __END__
  21. >>8  >>    :ENDOFPERL
  22. >>9  >>    some more DOS if you need it
  23. >>10 >>    rem Drop through end of Batch file
  24. >
  25. >Why does Perl skip over the GOTO?
  26.  
  27. Because it's inside a quoted string, the one which starts on line 1 and
  28. ends on line 5.  As far as perl is concerned, it's not a statement.
  29.  
  30. >That is a valid command in Perl
  31. >(even if illadvised). So in effect, both the batch and Perl
  32. >processors are interpreting the same file over again. Neat.
  33.  
  34. Yes, but for the most part they don't execute the same lines.  DOS doesn't
  35. execute lines 5 through 7, and perl doesn't execute 2-3 or 8-10. 
  36.  
  37. >How does the expansion of the %0-%9 parameters work? Apparently
  38. >this is done twice, once in the batch processor and again in the
  39. >Perl processor. Is that right? Thus which meta characters must be
  40. >escaped and Once or twice?
  41.  
  42. The parameters are expanded only by DOS.  They're inside single quotes and
  43. not expanded.  And even if they were, they'd still be inside a string, so
  44. nothing would happen. 
  45.  
  46. >I put all my batch files in a \bat directory which is on the path,
  47. >so the batch processor will find any bat file in it, I suppose I
  48. >still need the -s so that Perl will know to search the path as
  49. >well?
  50.  
  51. Yes.  Also, you can't call it as XYZ.BAT, only as XYZ. 
  52.  
  53. >By the way, in all the Perl stuff I have read so far, I keep seeing
  54. >references to "globbing", is this just another way of saying
  55. >"command line expansion"?
  56.  
  57. File name expansion. 
  58.  
  59. >>You do something similar using the -x command line  option instead of the -S
  60. >>command line option. 
  61. >
  62. >What's the difference between the two?
  63.  
  64. They're just different.  I think the -x form is easier to understand.
  65. There may be some drawbacks to it, but I haven't done anything complicated
  66. enough to run into them. 
  67.  
  68. Here's a simple example: 
  69.  
  70. ----- START -----
  71.  
  72. @echo off
  73. perl -x c:\batch\calc.bat
  74. goto :exit
  75.  
  76. #!perl
  77.  
  78. print 'Enter an expression: ';
  79.  
  80. while (<>)
  81.    {
  82.    print eval $_, "\n";
  83.    print $@;
  84.    last if !/\S/;
  85.    print 'Enter an expression: ';
  86.    }
  87.  
  88. __END__
  89.  
  90. :exit
  91.  
  92. ----- END -----
  93.  
  94. >P.S. I keep seeing references to "sockets" in the Perl docs. I have
  95. >no idea what this means, other than that it doesn't work in the DOS
  96. >versions of Perl. I assume it is a unix term. What does this mean
  97. >or do?
  98.  
  99. If I understand it correctly (which I might not - I'm not a networking
  100. person), sockets are a way to communicate with other programs via a
  101. network.  You can send messages through a socket and have them processed by 
  102. a machine somewhere on the other side of the world, maybe. 
  103.  
  104. I don't know why it doesn't work in the DOS versions of perl.  I assume
  105. that no one has gone to the trouble of compiling a version with socket
  106. support built in.  There are socket libraries available for PC's. 
  107.  
  108. -- 
  109.  
  110. -----------------------------------------------------------------------
  111. Jack Hamilton   jfh@netcom.com   P. O. Box 281107   SF, CA   94128-1107
  112.