in reply to Re: write to Disk instead of RAM without using modules
in thread write to Disk instead of RAM without using modules
Only the first file is ever loaded into memory. When you read the other files, you just update counters. Even if you have hundreds of files, it will work provided the first file can be loaded into the hash.my %seen; open my $FH, "<", "file1.txt" or die "cannot open ..."; while (<$FH>) { chomp; $seen($_) = 1; } close $FH; for my $other_file (qw/ file2.txt file3.txt file4.txt .../) { open my $FH, "<", $other_file or die "cannot open ..."; while (<$FH>) { chomp; if (exists $seen{$_}) { $seen{$_}++; } } close $FH; }
Update:: moved the second chomp line to the right place (within the while loop, not just before).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: write to Disk instead of RAM without using modules
by Anonymous Monk on Oct 26, 2016 at 05:06 UTC | |
by Laurent_R (Canon) on Oct 26, 2016 at 06:20 UTC | |
by Anonymous Monk on Oct 26, 2016 at 09:15 UTC | |
by Anonymous Monk on Oct 26, 2016 at 05:41 UTC | |
by Anonymous Monk on Oct 26, 2016 at 11:53 UTC | |
by Corion (Patriarch) on Oct 26, 2016 at 11:58 UTC | |
by haukex (Archbishop) on Oct 26, 2016 at 12:01 UTC | |
by Laurent_R (Canon) on Oct 26, 2016 at 22:31 UTC |