in reply to Re^2: 'and' greps
in thread 'and' greps

If you want to compare arrays there are more efficient ways. But to expand on grep{} in a list context, you can put anything you want inside the grep. If the *last line* in the grep is "true" then input is passed to the output.

Here is a simple example where what is in the grep{} has nothing to do with the input list...an odd/even flip-flopper. Perl grep can do some very cool things that command line grep can't!

#!/usr/bin/perl -w use strict; my @test = qw (a b c d e f); my $is_even_flag =1; my @odd_tests = grep {$is_even_flag ^= 1; }@test; print "@odd_tests"; #prints b d f