cool use for map
nkuipers
nkuipers at uvic.ca
Tue Oct 29 21:22:11 CST 2002
@found = map { $1 } $searchthis =~ m/($forthis)/g;
As written, it's not terribly useful unless you are interested in how many
times $forthis matches and put @found in scalar context. But if you
substitute a quantified character class for $forthis, suddenly you are
extracting from a sequence all runs of hydrophobic amino acid residues,
lowercase nucleotides, and so forth, all in one line. I didn't think you
could use a regex as the list context construct in map, but decided to try it
rather than rolling another clunky "while matches push array and return once
finished". Actually it's part of a method that maps to @found differently
using if-elsif-elsif... so the one-lining is much nicer on the eyes. Yay
Perl.
:)
Hope everyone is doing well,
Nathanael
More information about the Victoria-pm
mailing list