in reply to Coding styles using if/else

Personally, I think it could be somehow a pathological case such as an implicit return from a sub, assuming you're just trying to avoid having following code executed; the exit; statement is fine though, if you explicitly want to exit. In former case, it works well, as long as you don't change anything - but, all of a sudden, it may break if you do (possibly triggered by removing/commenting the exit; statement accidentally).

As a side note:

If you're worried about the total size of the if {} else {} clause, you could give the ternary conditional operator (?:) a try (assuming your code doesn't continue below the ternary operator statement in this peculiar case):

($name eq "") ? print q{Sorry, name can't be empty} : print "Thank you, $name. Your submission is complete.";

Replies are listed 'Best First'.
Re^2: Coding styles using if/else
by blazar (Canon) on Apr 24, 2007 at 11:27 UTC
    If you're worried about the total size of the if {} else {} clause, you could give the ternary conditional operator (?:) a try (assuming your code doesn't continue below the ternary operator statement in this peculiar case):
    ($name eq "") ? print q{Sorry, name can't be empty} : print "Thank you, $name. Your submission is complete.";

    (Sorry to reply so late but) this looks very wrong to me: the ternary operator is designed to operate on values, not to use it as a general purpose branching tool for its side effects. I would never do so except in golf: in particular the above example becomes perfectly fine if you amend it by factoring out the print:

    print +($name eq "") ? q{Sorry, name can't be empty} : "Thank you, $name. Your submission is complete.";