in reply to Re: CSV Pattern Matching
in thread CSV Pattern Matching
There's no need to pull the first file into memory. This is a fairly standard "load the filtering file into a hash and check the other file against it line-by-line" problem, with the one extra twist that, if the first field from the filtering file is a match, another field needs to be checked against the second field.
#!/usr/bin/env perl use Modern::Perl; my %k; open my $fd2, '<', 'file2.txt' or die $!; while(<$fd2>){ chomp; if( /([a-z]),(\d+)/ ){ # one lowercase character, a comma, and di +gits $k{$1} = $2; } } close $fd2; open my $fd1, '<', 'file1.txt' or die $!; while(<$fd1>){ my @w = split /, /; if( $k{$w[3]} and $w[5] =~ /$k{$w[3]}/ ){ print; } } close $fd1;
Aaron B.
My Woefully Neglected Blog, where I occasionally mention Perl.
|
|---|