On Jun 21, 4:11 am, [EMAIL PROTECTED] (Gowthamgowtham) wrote:
> Hello All,
>
> I found this in Programming Perl - 3rd edition. Could not understand how
> this works.
>
> #!/bin/sh -- # perl, to stop looping
>
> eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
>
>     if 0;
>
> Questions:
>
> -          Who (I mean which program/shell) runs eval 'exec .'?
>
> -          What is ${1+"$@"}, looks like this makes up the command line
> arguments to the script?
>
> -          What is the purpose of 'if 0;' on a new line?
>
> 'perldoc perlrun' documents that -S switch makes perl search $PATH for the
> script.

perldoc perlrun also says this:

          This example works on many platforms that have a shell
          compatible with Bourne shell:

              #!/usr/bin/perl
              eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
                      if $running_under_some_shell;

          The system ignores the first line and feeds the program
          to /bin/sh, which proceeds to try to execute the Perl
          program as a shell script.  The shell executes the
          second line as a normal shell command, and thus starts
          up the Perl interpreter.  On some systems $0 doesn't
          always contain the full pathname, so the -S tells Perl
          to search for the program if necessary.  After Perl
          locates the program, it parses the lines and ignores
          them because the variable $running_under_some_shell is
          never true.  If the program will be interpreted by csh,
          you will need to replace "${1+"$@"}" with $*, even
          though that doesn't understand embedded spaces (and
          such) in the argument list.  To start up sh rather than
          csh, some systems may have to replace the #! line with
          a line containing just a colon, which will be politely
          ignored by Perl.

--
Brad


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to