That isn't (mostly) Perl code. That is a "shell script". I think the first eval is trying to figure out what class of shell you are using. The second eval is for Bourne and compatible shells (/bin/sh, ksh, bash). The third eval is for the C shell.

"$@" is a way of passing in a bunch of arguments with each argument surrounded by quotes so that spaces and other special characters in the arguments don't get reinterpretted. Unfortunately, that passes in the single argument "" if no arguments were specified. ${1+...} means only do the "..." part if $1 is set so ${1+"$@"} is just the standard /bin/sh hack for passing the arguments that were passed to the shell script on to some other program without reinterpretting them.

$argv:p is the C shells way of doing the same thing.

eval is used so that Perl can parse that code well enough to see "if 0;" which tells it to not execute any of that code. The shells won't see "if 0;" until they've already run that code, by which point it will be too late because the shell will have been replaced by perl due to one of the execs.

This looks like a fairly standard "polyglot" (code that is valid in more than one language at once) kluge to get Perl to run a script even when faced with a Unix kernel and shell that are too stupid to recognize the #!/usr/bin/perl line at the top of the script. See perldoc perlrun for more info on this.

        - tye (but my friends call me "Tye")

In reply to (tye)Re: Confusing 'eval' code by tye
in thread Confusing 'eval' code by ask_chinna

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.