[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Re: Perl -Sx " 0 " "Parameters" ;



Philippe de Rochambeau wrote:

> A lot of the examples in the Ext:t: folder contain the following line:
> Perl -Sx "{0}" {"Parameters"}; Exit {Status}
> What does it mean?

It allows a following Perl script to be run by typing its name as a
MPW (Macintosh Programmer's Workshop) command.  The commands and
syntax are for MPW's shell.

    Perl           Start the Perl tool
    -Sx            The usual Perl -S and -x arguments
    "{0}"          Pass the name of the MPW script ({0} == argument 0),
                     with quotes around it to protect embedded spaces
                     Thus the MPW script is also the Perl script.  The
                     Perl -x argument causes Perl to ignore everything
                     up to a line containing "#!...perl", which usually
                     is the next line in the MPW script.  The {0} for
                     MPW is the same as $0 for Unix.
    {"Parameters"} Pass all other MPW command line parameters
                     as Perl script arguments, protecting embedded
                     spaces with quotes.  This is equivalent to $*
                     for Unix.
    ;              End of the "Perl..." MPW command
    Exit {Status}  When Perl terminates, after it is done executing
                     the script, the next MPW script command is Exit,
                     passing the return status of the most recently
                     executed command back to the MPW shell.  Thus,
                     the MPW shell quits after executing this line
                     and does not try to execute the Perl script.

For the Unix shells, similar behavior is caused by the familiar:

#!/usr/bin/perl

which causes a c shell or bash shell to stop executing the script
and instead turn execution over to the named program:  perl in
this case.

For DOS batch files, similar behavior is caused by enclosing the script
within the following batch file commands.  One clever part is the
"@rem = '..." statement, which is both a comment for the DOS batch
interpreter, and also soaks up all of the batch stuff into a harmless
one element array named @rem if seen by Perl. This allows you to run
the batch file either as a batch file, or by naming it as a script
in a Perl command line (for example: "perl -d filename.bat") without
needing to remember to use the -x argument.

@rem = '--*-Perl-*--
@echo off
perl -x -S %0.bat %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofperl
@rem ';
#!perl
#line 8

    # your Perl script goes here

__END__
:endofperl

--------------------------------
I move scripts around between different systems, and it took me a
while to discover all of this, so I thought it might be useful to
post it all here.

   -Paul-    paul.b.patton@hbc.honeywell.com

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch