From: jfh@netcom.com (Jack Hamilton)
Subject: Re: How to run a Perl under DOS?
Organization: Netcom - Online Communication Services (408 241-9760 guest)
Date: Fri, 8 Jan 1993 22:01:06 GMT

In article <1270@alsys1.aecom.yu.edu> manaster@yu1.yu.edu (Chaim Manaster) 
writes:
>
>>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
>
>Why does Perl skip over the GOTO?

Because it's inside a quoted string, the one which starts on line 1 and
ends on line 5.  As far as perl is concerned, it's not a statement.

>That is a valid command in Perl
>(even if illadvised). So in effect, both the batch and Perl
>processors are interpreting the same file over again. Neat.

Yes, but for the most part they don't execute the same lines.  DOS doesn't
execute lines 5 through 7, and perl doesn't execute 2-3 or 8-10. 

>How does the expansion of the %0-%9 parameters work? Apparently
>this is done twice, once in the batch processor and again in the
>Perl processor. Is that right? Thus which meta characters must be
>escaped and Once or twice?

The parameters are expanded only by DOS.  They're inside single quotes and
not expanded.  And even if they were, they'd still be inside a string, so
nothing would happen. 

>I put all my batch files in a \bat directory which is on the path,
>so the batch processor will find any bat file in it, I suppose I
>still need the -s so that Perl will know to search the path as
>well?

Yes.  Also, you can't call it as XYZ.BAT, only as XYZ. 

>By the way, in all the Perl stuff I have read so far, I keep seeing
>references to "globbing", is this just another way of saying
>"command line expansion"?

File name expansion. 

>>You do something similar using the -x command line  option instead of the -S
>>command line option. 
>
>What's the difference between the two?

They're just different.  I think the -x form is easier to understand.
There may be some drawbacks to it, but I haven't done anything complicated
enough to run into them. 

Here's a simple example: 

----- START -----

@echo off
perl -x c:\batch\calc.bat
goto :exit

#!perl

print 'Enter an expression: ';

while (<>)
   {
   print eval $_, "\n";
   print $@;
   last if !/\S/;
   print 'Enter an expression: ';
   }

__END__

:exit

----- END -----

>P.S. I keep seeing references to "sockets" in the Perl docs. I have
>no idea what this means, other than that it doesn't work in the DOS
>versions of Perl. I assume it is a unix term. What does this mean
>or do?

If I understand it correctly (which I might not - I'm not a networking
person), sockets are a way to communicate with other programs via a
network.  You can send messages through a socket and have them processed by 
a machine somewhere on the other side of the world, maybe. 

I don't know why it doesn't work in the DOS versions of perl.  I assume
that no one has gone to the trouble of compiling a version with socket
support built in.  There are socket libraries available for PC's. 

-- 

-----------------------------------------------------------------------
Jack Hamilton   jfh@netcom.com   P. O. Box 281107   SF, CA   94128-1107
Newsgroups: comp.lang.perl