Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^4: exit this way

by Your Mother (Archbishop)
on Sep 01, 2015 at 15:45 UTC ( [id://1140681]=note: print w/replies, xml ) Need Help??


in reply to Re^3: exit this way
in thread exit this way

:P The last expression of a sub/block/package is its return value; when there is no explicit return. So that little snippet just rotates returning "true" and "false" randomly; idiom: return 0 or 1 element of anon array with 2 elements, one true, one false. By adding a print you made the sub always return "true."

exit values are approximately opposed to return/success values in most Perl. The bang (!) performs this inversion. exit == 0 means success, any other value (-1, 1 .. 255) means some flavor of fail (on *nix anyway). Why I suggest it is cognitively a bad idea for a Perl script. To test the original, try these instead (with 1140673.pl being the first scriptlet I posted)-

moo@cow~>1140673.pl && echo "I CAN HAZ SUCCEED?" moo@cow~>1140673.pl || echo "FAIL!"

Replies are listed 'Best First'.
Re^5: exit this way
by 1nickt (Canon) on Sep 01, 2015 at 16:16 UTC

    OK, I see. Ugh, the Vague One obfuscated my thoughts ... I was focusing on whether the sub would be executed when called as the argument to exit(), rather than what that would make the output of the script via exit(). Thanks.

    The way forward always starts with a minimal test.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1140681]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-18 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found