in reply to Style: expr or warn vs. if..warn?
I like this rule-of-thumb: Use if/unless for checking a condition. Use and/or when the statement does something with side-effects.
Clearly there's a bit of overlap between "checking a condition" and "doing something with side-effects." In the event of a tie, I wholeheartedly agree with hossman that the most important part of the statement should be at the beginning, because it's easier to skim the code.do_something_complex() or die; do_something_complex() and then_do_something_else(); # condition checking: die "terribly" if $condition; die "terribly" unless $obj->can("foo");
Also, don't forget to consider the surrounding code. If you have a bunch of guard statements in a row that try to do/check something or else die/return, make them all the same structure!
blokhead
|
|---|