I want to filter elements of @array
which begin with elements of @search
:
my @array = \
For this kind of search, you can easily use index
say (@array X @search).grep( { defined($^a[0].index($^a[1])) } )
.grep( { $^a[0].index($^a[1]) == 0 } );
This creates a list of Cs, and seeks the second element of the pair within the first; it returns only the list of those that appear in the first position. defined
is needed because it will return Nil
if it does not find it. It's not faster than your alternative above, but it's in the same ballpark, with 0.03 system time and ~ 0.30 seconds