in reply to Read the two files
For large files (230K lines is at the small end of large) slurping files is a bad idea. In this case reading the second file first and building a lookup hash, then reading the first file and testing against the hash is probably the way to go. Consider:
use strict; use warnings; my $file1Str = <<END_FILE1; 2000/01/03/aaa/xyz.xml 2002/04/01/bbb/abc.xml END_FILE1 my $file2Str = <<END_FILE2; 2000/01/03/xyz END_FILE2 my %lookup; open my $file2In, '<', \$file2Str or die ("Could not open file!"); while (my $line = <$file2In>) { my @parts = split '/', $line; my $key = join '/', @parts[0 .. 3]; ++$lookup{$key}; } close $file2In; open my $file1In, '<', \$file1Str or die ("Could not open file!"); while (my $line = <$file1In>) { my @parts = split '/', $line; $parts[-1] =~ s/\.xml//i; my $key = join '/', @parts[0 .. 2, 4]; next if exists $lookup{$key}; print $line; } close $file1In;
Prints:
2002/04/01/bbb/abc.xml
Update Fixed wording - thanks jethro
|
|---|