Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: What is the intention and logic of this line in the beginning of the script?

by cdarke (Prior)
on Oct 12, 2011 at 10:33 UTC ( #930974=note: print w/replies, xml ) Need Help??

in reply to What is the intention and logic of this line in the beginning of the script?

As moritz said, this is actually a shell command. eval is both a shell and a Perl command, but in this case it is the shell version.

In most UNIX shells (not csh), $? is the status of the previous command (in Perl it is the exit status of the previous child process - not the same thing). In a shell, parentheses create a sub-shell which is a new shell environment (I use the term loosly) in the same process, so eval '(exit $?0)' in shell exits the sub-shell (not the current process). In shells, an evaluation of non-zero is considered false, and 0 is considered true (consider 0 to be 'success').

exec also is in both shells and Perl, and it replaces the current program with a new one in the same process, so it will replace the shell with perl.

In this case, the if 0 will be considered part of the command by a shell. However, in Perl the if 0 has precedence, so none of that will be executed if we are running perl, zero being false in perl (and most languages). Try:
print "A " && print "B " && print "C " if 0;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://930974]
[Lady_Aleena]: I'll just have to search for the files using the subs and open them up.
[Discipulus]: nice Perl dreams, folks.. shower->Dumas->bed
[erix]: pere ou fils?
[Lady_Aleena]: Discipulus, good night.
[Discipulus]: pere, le vicomte de bragelonne.. wonderfull
[erix]: I'll keep that in mind (haven't read), buona notte :)

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2017-05-23 19:57 GMT
Find Nodes?
    Voting Booth?