in reply to Re: how to get the full array value if part of the element matches
in thread how to get the full array value if part of the element matches
my @matches = grep { $_ =~ /aa/i } @array; print "Matched:$_\n" for @matches;
Since the nature of the question itself clearly shows that the OP is a complete newbie, I think it may be worth to add that it's not necessary to pass through an intermediate @matches variable (before he cargo cults such an use), although in other cases it could, and in some others it may be convenient anyway:
print "Matched:$_\n" for grep { $_ =~ /aa/i } @array;
But wait! Here you have two loops, of which one implicit in grep, whereas one would suffice. Hence a solution like that of fenLisesi may be preferable, but (to the OP!) be warned that it doesn't really matter in terms of performance.
|
|---|