Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Coding styles using if/else

by shmem (Chancellor)
on Apr 05, 2007 at 23:09 UTC ( [id://608572]=note: print w/replies, xml ) Need Help??


in reply to Re: Coding styles using if/else
in thread Coding styles using if/else

You wrote
I would think this would be better:
exit "Sorry, name can't be empty" if $name eq '' ;

It's not, as per perldoc -f exit

exit EXPR
exit Evaluates EXPR and exits immediately with that value. Example:
...

Your code does exit 0 if $name eq '' which may or may not be what is intended, but what looks like a message being printed - isn't. Try at your shell

perl -e 'exit "foo"'; echo $?

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^3: Coding styles using if/else
by bart (Canon) on Apr 06, 2007 at 18:02 UTC
    For this kind of usage, with an error message, he should use die instead of exit.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-03-29 12:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found