Re: mini-quiz

Ronald J Kimball <[email protected]> Wed, 20 Jun 2007 10:17:50 -0400
Newsgroups gmane.comp.lang.perl.qotw.discuss
Message-ID <[email protected]>
On Tue, Jun 19, 2007 at 11:25:35AM -0400, Joshua Kronengold wrote:
> On Tue, 19 Jun 2007 12:50am, Ron Isaacson wrote:
> >Joshua Kronengold wrote:
> >> >>  my $country = map +(/^(?:|gbr)$/ ? '' : uc),$card->country;
> >>
> >> [...] is much better.
> 
> >Sorry, but you lost me there. I consider myself to be a pretty darn
> >good perl programmer, and even I'd have to read that line a few times
> >to understand its meaning.
> 
> *blink*  really?  which part and why?  Is some of this idiomatic 
> unfamiliarity? Would this help?
> 
> my $country = map +(/^(?:|gbr)$/ ? '' : uc "[$_]") =>
>                        $card->country;
> 
> How about:
> my %ignored = map +($_ => undef) => ('', qw(gbr)):
> 
> my $country = map +(exists $ignored{$_}
>                           ? ''
>                           : uc "[$_]") => $card->country;

Well, the fact that map in scalar context returns the number of items
generated suggests that there is something to be said for not trying to be
too clever with Perl idioms...  ;)

Ronald