Confusion in perlrun documentation

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi, I've been trying out a2p and found these lines at the top of the
perl output:

eval 'exec /usr/bin/perl -S $0 $'
    if $running_under_some_shell;

Googled around for this and found several links to perlrun that
attempt to explain what this idiom does exactly but I am confused
about the part where the shell exec's /usr/bin/perl with the script
name and its arguments and then .... "ignores the lines parsed from
the script because the $running_under_some_shell variable is always

Where is the glue between parsing lines and ignoring them due to this
undefined variable? How is this happening exactly? Could anyone please
explain in a simpler language what is happening?


Re: Confusion in perlrun documentation

On Fri, 20 Mar 2009 04:49:20 -0700, Krishna Chaitanya wrote:

Quoted text here. Click to load it

This construct is meant for ancient systems that don't know what #!
means and pass every script to /bin/sh.  (Anyone know whether any such
systems are still in use?)

The lines are written so that they do the right thing in both /bin/sh
and perl.  When /bin/sh reads the first line, it interprets it as
meaning, "run perl on this file and pass it the arguments I was given",
which is what you want.  When perl runs the file - whether because it
was started on it originally due to being on a nonbroken system or whether
because it was started by the eval line - it reads the eval line but being
perl, then reads the next line to see the rest of the statement, and
ignores it because $running_under_some_shell was never set and is
therefore undef, hence false.  Then it goes on with the rest of the


Peter Scott / /

Re: Confusion in perlrun documentation

Quoted text here. Click to load it

And here we have that fabulous I<-w> story again.  Or not.

Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom

Site Timeline