cool use for map
abez
abez at abez.ca
Tue Oct 29 21:30:35 CST 2002
For stuff like this remember to give a good comment :)
You'll come back to this later and make a doubletake unless you give a
reasonable comment.
One line is great but your comments will probably have to be pretty large.
Ahh, the responsibilities that come with great power :)
On Tue, 29 Oct 2002, nkuipers wrote:
> @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
>
--
abez----- ----- ------ - ------ -- ------------
http://www.abez.ca/ Abram Hindle (abez at abez.ca)
--- --- ------ --------- - - ------ --------abez
More information about the Victoria-pm
mailing list