in reply to Grep inside the while Loop
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 |