https://issues.apache.org/SpamAssassin/show_bug.cgi?id=6312
--- Comment #6 from Mark Martinec <[email protected]> 2010-02-01 09:08:49 UTC --- > I just find it odd to use a ternary operator with empty clauses It's not with an empty clause. It's with an empty list as an expression. Arguments to a ternary conditional operator are expressions, not clauses (which makes it different to if-else). > Perhaps my assumptions of perl's short-circuiting nature is incorrect It is not incorrect. > but I was under the impression something like 'true && false && undef' > wouldn't be a problem because it would stop everything once you get the > false clause. True. Again ours may not be the best example, as the subroutine in question would be just as happy receiving undef at the options argument, or no argument at all, so your suggestion is just as good here. But some other routines take optional arguments directly, not wrapped in an anonymoush hash. The choice of short-circuiting boolean ops vs. the ternary would make a difference there. For example: sub x { my($f1, $f2, %opt) = @_; print $opt{xxx} if defined $opt{xxx}; } now the calls: x(1,2, 1 ? () : (xxx => 3)); x(1,2, 0 ? () : (xxx => 3)); 3 x(1,2, 1 && (xxx => 3)); 3 x(1,2, 0 && (xxx => 3)); Odd number of elements in hash assignment at -e line 1. So, yes, your code is just fine for the case where optional argument is chosen to be a dynamically generated hash. Mine is applicable to either case. It is a rather thin line to base a decision here, and largely a matter of preference - I somehow prefer to use the ternary, which works equally well in both cases. > As to the statement standing within an expression ... again, my green perl > nature shines. I guess that's why it was ternary, so as to avoid the extra > curly brackets and/or a 'do' stanza? Exactly. The do { if (...) { ... } } is a lot of clutter, I try to avoid it within an expression. -- Configure bugmail: https://issues.apache.org/SpamAssassin/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug.
