I expanded your code to show relevance to the OP's question.
Your map shows something that took me a long time to figure out,
how to return "nothing" from a map{}!
I think this code is well past what the OP wanted.use strict; use warnings; my @x = ("aaBxyz", "..Bxys", "bbxyzzy", "xxAx"); my @result = map { /^..(A|B)./ ? [ $1, $_ ] : () } @x; # @result is a "2-d array", references to "rows of array" # I swapped $1 and $_ because I thought the print out looked better # Of course every map{} can be expressed as a for loop... foreach my $row_ref (@result) { print "@$row_ref\n"; } =PRINTS: B aaBxyz B ..Bxys A xxAx =cut
ADDED: If the OP wants a subset of something, think GREP. If the OP wants to transform an input into something else, think MAP.
In reply to Re^2: do $n exist in grep?
by Marshall
in thread do $n exist in grep?
by misterperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |