in reply to understanding eval in HPOJ
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 ]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: understanding eval in HPOJ
by GhodMode (Pilgrim) on Apr 06, 2004 at 04:27 UTC |