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.";
In reply to Re^2: Coding styles using if/else
by blazar
in thread Coding styles using if/else
by sulfericacid
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |