in reply to Grep inside the while Loop

Apparently, you have solved your problem. I'd like to point out that you could use the any function from the CPAN List::MoreUtils module as an alternative to the grep built-in function. One advantage is that any will stop searching through your array as soon as it finds a match, whereas grep will always search through the entire array. Therefore, any has the potential of being faster.

Another advantage (in my opinion) is that it makes the code slightly more readable, as do some other CPAN modules, such as File::Slurp and autodie (now a core pragma as of perl 5.10). Consider the following re-write of your code (UNTESTED since you did not provide input data):

use strict; use warnings; use autodie; use File::Slurp qw(slurp); use List::MoreUtils qw(any); my @list_match = slurp('Data.txt'); chomp @list_match; open my $fh, '<', 'Data_Large.txt'; while (<$fh>) { my $item = (split)[2]; print "Found $item\n" if any {$item eq $_} @list_match; } close $fh;

Or, better yet... use a hash.

Replies are listed 'Best First'.
Re^2: Grep inside the while Loop (any)
by snape (Pilgrim) on Oct 21, 2010 at 08:19 UTC

    Thanks toolic