Re: mini-quiz

Joshua Kronengold <[email protected]> Mon, 18 Jun 2007 14:36:33 -0500
Newsgroups gmane.comp.lang.perl.qotw.discuss
Message-ID <[email protected]>
Yitzchak Scott-Thoennes writes:
>    my $country = $card->country;
>    $country = $country eq 'gbr' ? '' : uc "[$country]" if $country;

I personally don't like tail ifs, but that's (mostly) a personal
prejudice.

I also don't much like testing string usefulness by truth (what if
country is "0"?), or overloading variables by having them hold a temp
variable.

And the fact that the code appears to be implicitly retaining a
presumed empty string (but as above, can end up retaining 0 instead)
is just awful.

So I'd probably just do:

my $country = map +(/^(?:|gbr)$/ ? '' : uc),$card->country;

But if I were to "cleverly" remove the tail if, I'd do something like
this:

$country &&= $country eq 'gbr' ? '' : uc "[$country]";


-- 
       Joshua Kronengold (mneme@(io.com, labcats.org)) |\      _,,,--,,_  ,)
--^--   "Did you know, if you increment enough, you   /,`.-'`'   -,  ;-;;'
 /\\    get an extra digit?"  "I knew," weeps Six.    |,4-  ) )-,_ ) /\     
/-\\\   "We knew. But we had forgotten."	     '---''(_/--' (_/-'