in reply to how to get the full array value if part of the element matches

I think you want something like:
my @matches = grep { $_ =~ /aa/i } @array; print "Matched:$_\n" for @matches;

Cheers,
Darren :)

  • Comment on Re: how to get the full array value if part of the element matches
  • Download Code

Replies are listed 'Best First'.
Re^2: how to get the full array value if part of the element matches
by blazar (Canon) on Oct 20, 2006 at 18:54 UTC
    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.