This looks at first glance that it was intended as a polyglot incantation. That means it is meant for BOTH bash and for perl to read and act accordingly. These are very ugly and fickle, especially if something changes in the operating environment.

There's a related example in perlrun, which may shed some light. The key features of these perl/shell polyglots are that they

IF perl runs it, AND the internationalization $ENV{LANG} isn't set to the POSIX C setting, THEN the script will try to RESTART the script via the shell, with the appropriate environmental fix.

IF on the otherhand, a shell runs it, THEN the if line is completely ignored since it doesn't get that far. The exit/exec pair see to that.

The tortured use of confusing clauses like eval 'somestring' are just a side effect to ensure that it does the right thing in both cases, errors and warnings be damned.

On Linux and many Un*x varieties, the kernel reads the shebang line and decides that the perl interpreter must be used if not otherwise specified. On DOS/Windows, and on some Un*x varieties, there is no such assumption that the shebang must be inspected. So these polyglots are sometimes used to ensure that the right interpreter is run. (CMD.EXE/PERL.EXE polyglots are even uglier.)

(Sorry I'm not at a station where I can play with this further.)

--
[ e d @ h a l l e y . c c ]


In reply to Re: understanding eval in HPOJ by halley
in thread understanding eval in HPOJ by GhodMode

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.