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.