George_Sherston has asked for the wisdom of the Perl Monks concerning the following question:
I'm just starting to get to grips with map and wondering what more I can do with it. Is it possible to do conditional mapping? To take the example in map, say I have an array
Am I barking up the wrong tree? Which tree would you recommend?
§ George Sherston
and I want to make a hash using all but words beginning in 'f' as values,my @array = qw/ foo bar baz bodkin /;
works, but is there an equivalent usage with map?my %hash2 = (); foreach $_ (@array) { $hash2{getkey($_)} = $_ unless /^f/; }
doesn't work.my %hash1 = map {getkey($_) => $_ unless /^f/} @array;
Am I barking up the wrong tree? Which tree would you recommend?
§ George Sherston
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Conditional Map?
by broquaint (Abbot) on Oct 07, 2002 at 11:33 UTC | |
Re: Conditional Map?
by blakem (Monsignor) on Oct 07, 2002 at 11:45 UTC | |
Re: Conditional Map?
by seattlejohn (Deacon) on Oct 07, 2002 at 14:04 UTC |
Back to
Seekers of Perl Wisdom