in reply to Re^3: Use grep with two arrays
in thread Use grep with two arrays

Um, I think this suggestion, as you originally posted it, will not work as you intend/expect:
@array1 = @array1[+grep { $array1[$_] =~ /keep these/ } 0 .. $#array1 ]; @array2 = @array2[+grep { $array1[$_] =~ /keep these/ } 0 .. $#array1 ];
When you process @array2, @array1 is presumably shorter than it used to be -- the elements of the two arrays are no longer in parallel (assuming they were parallel before the first grep operation). You'll be getting the wrong elements left behind in @array2 (only the last elements of @array2 will ever be removed).

Replies are listed 'Best First'.
Re^5: Use grep with two arrays
by QM (Parson) on Feb 15, 2006 at 20:53 UTC
    Yes, of course. Put it's supposed to DWIM, even if I ask the impossible, right? ;)

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of