(exit $?0) - challenge

A

Ara.T.Howard

gurus-

i've got a really strange looking bit of perl i'm trying to grok and it's been
too long since i've been in perl mode. actually, i'm not sure i'd ever have
gotten this one - any insight appreciated:


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

# ... the rest is a really normal looking perl script


regards.

-a
--

ATTN: please update your address books with address below!

===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| STP :: http://www.ngdc.noaa.gov/stp/
| NGDC :: http://www.ngdc.noaa.gov/
| NESDIS :: http://www.nesdis.noaa.gov/
| NOAA :: http://www.noaa.gov/
| US DOC :: http://www.commerce.gov/
|
| The difference between art and science is that science is what we
| understand well enough to explain to a computer.
| Art is everything else.
| -- Donald Knuth, "Discover"
|
| /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done'
===============================================================================
 
B

Ben Morrow

gurus-

i've got a really strange looking bit of perl i'm trying to grok and
it's been too long since i've been in perl mode. actually, i'm not
sure i'd ever have gotten this one - any insight appreciated:

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

This line is not actually Perl :).

It is a trick to make the script run on systems that don't support the
#! syntax. On (some of) those systems, executing a text file always
tries to run it as a shell script, and this line is to make the shell
re-execute the script with perl. The 'if 0' at the end means that perl
will always ignore the entire line. I don't fully understand the shell
magic: my guess would be that it is supposed to work under both sh and
csh, but my knowledge of shell is not that good.

If your system understands #!, you can just take it out.

Ben
 
A

Ara.T.Howard

Date: Fri, 14 Nov 2003 00:33:16 +0000 (UTC)
From: Ben Morrow <[email protected]>
Newsgroups: comp.lang.perl.misc
Subject: Re: (exit $?0) - challenge




This line is not actually Perl :).

It is a trick to make the script run on systems that don't support the
#! syntax. On (some of) those systems, executing a text file always
tries to run it as a shell script, and this line is to make the shell
re-execute the script with perl. The 'if 0' at the end means that perl
will always ignore the entire line. I don't fully understand the shell
magic: my guess would be that it is supposed to work under both sh and
csh, but my knowledge of shell is not that good.

If your system understands #!, you can just take it out.

i'd hoped as much - i had a vague feeling that the (exit) syntax was creating
a subshell or something - but couldn't find any reference to it in perlsyn.
guess that's because it's not perl.

thanks!

-a
--

ATTN: please update your address books with address below!

===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| STP :: http://www.ngdc.noaa.gov/stp/
| NGDC :: http://www.ngdc.noaa.gov/
| NESDIS :: http://www.nesdis.noaa.gov/
| NOAA :: http://www.noaa.gov/
| US DOC :: http://www.commerce.gov/
|
| The difference between art and science is that science is what we
| understand well enough to explain to a computer.
| Art is everything else.
| -- Donald Knuth, "Discover"
|
| /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done'
===============================================================================
 
B

Ben Morrow

--

ATTN: please update your address books with address below!

=============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| STP :: http://www.ngdc.noaa.gov/stp/
| NGDC :: http://www.ngdc.noaa.gov/
| NESDIS :: http://www.nesdis.noaa.gov/
| NOAA :: http://www.noaa.gov/
| US DOC :: http://www.commerce.gov/
|
| The difference between art and science is that science is what we
| understand well enough to explain to a computer.
| Art is everything else.
| -- Donald Knuth, "Discover"
|
| /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done'
=============================================================================

I should trim that down a bit... I believe four lines is normally
considered sufficient.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

tk file dialog and directories 3
io/nonblock 4
puts(derived_from_array) 0
[RCR] Kernel#hostname 0
(Process.wait2)[1] 1
make MISSING=flock.o 0
pp equiv of #inspect 1
[BUG] greedy gsub 1

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top