Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpcc05!hparc0!dak From: dak@hparc0.HP.COM (Dave Kruger) Newsgroups: comp.lang.perl Subject: Re: MS Perl Questions Message-ID: <1170002@hparc0.HP.COM> Date: 6 Mar 91 02:00:29 GMT References: <1991Mar1.041441.4810@ccu1.aukuni.ac.nz> Organization: HP Australasian Response Centre (Melbourne) Lines: 96 > I just ran this on my ms-dos pc. > > @REM=(" > @c:\usr\perl %0.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 > @exit ") if 0; > > print "hello world\n"; > Well, I just ran this (I called it sneg.bat) on *my* ms-dos pc [sic], and got the following response ([D:\TMP] HH:MM is my MS-DOS prompt): [D:\TMP] 11:14 sneg Parameter format not correct - "hello hello world [D:\TMP] 11:14 [D:\TMP] 11:14 print "hello world\n"; Parameter format not correct - "hello By the way, I'm running the Beta version of MS-DOS 5.0. However, the following works well: @rem=" @perl -s %0.BAT %1 %2 %3 %4 %5 %6 %7 %8 %9 @goto exit "; # Print a mindless message print "hello world\n"; # DOS exit label. @rem=" :exit "; In the first example, I don't see any way that DOS could fail to fall through to, and try to execute the perl commands. My example jumps over them. For tyros (of which I am one) here is an explanation: COMMAND.COM handles this file as follows: (i) the first line is a comment, (ii) for the second line, it executes perl using this very batch file as input along with any other arguments that the batch file was invoked with, (iii) when perl finishes, control falls through to the third line and goes to the :exit label, (iv) at the :exit label, the batch file terminates and control passes back to the command line. (Please pick me up on any errors in this bit--as I say, I'm a perl tyro. If I'm in error, a gentle reminder will do--please send all flames to /dev/null.) Perl handles this file as follows: (i) the first three lines are legal perl code; they define an array called REM that has one element consisting of the string "\n@perl -s %0.BAT %1 %2 %3 %4 %5 %6 %7 %8 %9\n@GOTO exit ", (ii) perl then executes the print statement, (iii) again, the final two lines are legal perl code; they redefine the REM array to contain the string "\n:exit ", (iv) perl returns control to the calling batch file, %0.BAT. The REM array is never used or referenced by the perl commands--it is a convenience only. 4DOS USERS PLEASE STAND UP! =========================== This all works as expected under MS-DOS's COMMAND.COM, however, I'm getting the following behaviour under 4DOS (a shareware replacement for COMMAND.COM that is approximately 3 million times better--MS-DOS 5.0 addresses some of the limitations like aliasing and command history, but still falls a *long* way short of 4DOS): When you execute this command under 4DOS, it prints the message alright, but instead of falling through to the :exit label, it continues through the file, trying to execute each line of perl code as a DOS command: [d:\tmp] 11:28 sneg No closing quote hello world No closing quote # Print a mindless message Unknown command "#" print "hello world\n"; Parameter format not correct - "hello # DOS exit label Unknown command "#" No closing quote 4DOS doesn't like the single, double-quote when it parses the third line. I've tried doubling the quote, but then perl complains. Apparently, MS-DOS proceeds as soon as it has parsed enough of the line to do so (in this case, after it has read @GOTO exit). However, 4DOS keeps reading the line, finds the unmatched quote, complains, ignores the line completely, and falls through to the next line. Can anyone suggest any way around this problem? Any help will be really appreciated. Dave K. =============================================================================== Phone: +613 579 1254 (Home) InterNet: dak@hpauto.hpausa1.hp.com +613 895 2798 (Work) +613 898 9257 (FAX) ===============================================================================