NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Much like barbie… (Score:1)
… only I’d write the conditional the other way around:
Reply to This
Re: (Score:1)
Oops, that’s not actually the same. Well, it might be OK; if zeroes and undefs are not valid values that you need to care about, then that is how I’d write it.
If you do need to distinguish, though, then I’d put it this way:
Re: (Score:2)
Re: (Score:1)
Did you miss the part where I said this complex solution is only necessary if undef and zero need to be preserved? Sure this one is complex – because a three-way condition is always complex.
Re: (Score:2)
(I swapped the uc and gbr check around, because it makes the code prettier IMO.)
Though what's really needed in this code, regardless of the Perl syntax used, is a comment stating its intention. Perhaps:
Re: (Score:1)
Didn’t you just exclaim in another comment that you refuse to have this as a default style? Personally I find nested ternaries, if they’re laid out like a table, much easier to read than imperative code with a pile of temporary variables doing the same thing. Much easier to maintain, too.
Re: (Score:2)
As for comments: they provide redundancy. When the comment and the code are no longer in sync, that's a good sign something's wrong, and that helps to write good code.