est has asked for the wisdom of the Perl Monks concerning the following question:
file-1: file-2 1000 - foo 2000 2000 - bar 3000 3000 - fubar .... ... 990000 1000000 - heck
use autodie qw(open close); open my $fip, '<', 'file-1'; open my $fop, '<', 'file-2'; LINE1: while (my $line1 = <$fip>) { my @token = split(/-/, $line1, 2); while (my $line2 = <$fop>) { chomp $line2; if ($token[0] == $line2) { print $line1; next LINE1; } } } close $fip; close $fop;
use autodie qw(open close); open my $fip, '<', 'file-1'; open my $fop, '<', 'file-2'; my %record_id; while (my $line = <$fop>) { chomp $line; $record_id{$line} = 1; } close $fop; while (my $line = <$fip>) { my @token = split(/-/, $line, 2); if ( exist $record_id{$token[0]} ) { print $line; } } close $fip;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Matching data between huge files
by BrowserUk (Patriarch) on Aug 27, 2008 at 08:05 UTC | |
|
Re: Matching data between huge files
by Corion (Patriarch) on Aug 27, 2008 at 07:45 UTC | |
|
Re: Matching data between huge files
by tilly (Archbishop) on Aug 27, 2008 at 07:57 UTC | |
|
Re: Matching data between huge files
by JavaFan (Canon) on Aug 27, 2008 at 10:54 UTC | |
by gone2015 (Deacon) on Aug 27, 2008 at 13:18 UTC | |
by est (Acolyte) on Aug 28, 2008 at 00:54 UTC | |
|
Re: Matching data between huge files
by moritz (Cardinal) on Aug 27, 2008 at 07:51 UTC | |
by Corion (Patriarch) on Aug 27, 2008 at 08:00 UTC |