Suresh Govindachar wrote:

>   >>   1) What does the following line do? 
>   >> 
>   >>     eval 'exec C:\opt\perl\bin\perl.exe -S $0 ${1+"$@"}'
>   >>         if 0;
>   >
>   > That's just running perl against the bat file.
>   
>   But doesn't the if 0 condition mean that nothing happens?
>   (The call to perl to run the bat file from the shebang line 
>   onwards happens with a dos-cmd line).

This is a bunch of convoluted code at the beginning of the bat file to get
perl to read the file regardless of what shell it's runining in.  Read
perlrun man page for more info - esp on -S switch :

    -S   makes Perl use the PATH environment variable to search for the program
         (unless the name of the program contains directory separators).

         On some platforms, this also makes Perl append suffixes to the filename
         while searching for it. For example, on Win32 platforms, the ".bat" and
         ".cmd" suffixes are appended if a lookup for the original name fails,
         and if the name does not already end in one of those suffixes. If your
         Perl was compiled with DEBUGGING turned on, using the -Dp switch to
         Perl shows how the search progresses.

         Typically this is used to emulate #! startup on platforms that don't
         support #!. Its also convenient when debugging a script that uses #!,
         and is thus normally found by the shell's $PATH search mechanism.

         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. Other
         systems can't control that, and need a totally devious construct that
         will work under any of csh, sh, or Perl, such as the following:

                 eval '(exit $?0)' && eval 'exec perl -wS $0 ${1+"$@"}'
                 & eval 'exec /usr/bin/perl -wS $0 $argv:q'
                         if $running_under_some_shell;

         If the filename supplied contains directory separators (i.e., is an
         absolute or relative pathname), and if that file is not found,
         platforms that append file extensions will do so and try to look for
         the file with those extensions added, one by one.

         On DOS-like platforms, if the program does not contain directory
         separators, it will first be searched for in the current directory
         before being searched for on the PATH. On Unix platforms, the program
         will be searched for strictly on the PATH.

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to