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
Back to
Seekers of Perl Wisdom