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

This may be what you're after:

use strict; use warnings; my @array = ( "file1:aa" , "file2:bb" , "file3:cc" ); my( @found ) = grep { $array[$_] =~ m/aa/ } 0 .. $#array; print "Matched in $array[$_]\n" foreach @found;

Update
I wanted to point out that the difference between my implementation, and McDarren's is that his caches the elements from @array that matched, and mine caches the indices of the elements from @array that matched. It's up to you to decide which is better for you. There are subtle advantages to each.


Dave

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