I have tried to "undef" the array and that removes that RAM problem, but it still seems to slow down. (besides, if I did not "undef" the array, it would carry over and create some really massive files. The current file sizes average about 220Mb.
foreach $key (sort keys %fcnt) {
$fileNum = "001";
while (-e "$key-$run-$fileNum.txt"){
undef (%washOut);
open (FILE, "<$key-$run-$fileNum.txt");
print qq|Load/De-duping file (internal):\n|;
while (<FILE>) {
$tcnt++;
$twash = $_;
chomp($twash);
unless ($washOut{$twash}){
$washOut{$twash} = 1;
$cnt++;
if ($x >= 1000){ print qq|- $cnt\n|; $x = 0; }
$x++;
}
}
close(FILE);
print qq|$tcnt Scanned\n$cnt Loaded.\nSave Deduped Info...\n|;
open ($fileNum, ">$key-$run-$fileNum.new");
foreach (keys (%washOut)){ print $fileNum qq|$_\n|; }
close($fileNum);
print qq|Renaming original .txt to .old file...\n|;
rename ("$key-$run-$fileNum.txt", "$key-$run-$fileNum.old");
print qq|Renaming extract .new file to .txt file...\n|;
rename ("$key-$run-$fileNum.new", "$key-$run-$fileNum.txt");
print qq|Deleting .old file...\n|;
unlink ("$key-$run-$fileNum.old");
print qq|Saved... Continuing...\n|;
$fileNum++;
$nextFile = $fileNum;
# Wash against other files
if (-e "$key-$run-$nextFile.txt"){
$x = 0; $cnt = 0; $tcnt = 0;
while (-e "$key-$run-$nextFile.txt"){
open (FILE, "<$key-$run-$nextFile.txt");
open (FILEout, ">>$key-$run-$nextFile.new");
print qq|Loading and de-duping file (external):\n|;
while (<FILE>){
$tcnt++;
$twash = $_;
chomp($twash);
unless ($washOut{$twash}){
print FILEout qq|$twash\n|;
$cnt++;
if ($x >= 100000){ print qq|-|; $x = 0; }
$x++;
}
}
close(FILEout);
close(FILE);
print qq|Renaming original .txt to .old file...\n|;
rename ("$key-$run-$nextFile.txt", "$key-$run-$nextFile.old");
print qq|Renaming extract .new file to .txt file...\n|;
rename ("$key-$run-$nextFile.new", "$key-$run-$nextFile.txt");
print qq|Deleting .old file...\n|;
unlink ("$key-$run-$nextFile.old");
$nextFile++;
}
}
}
}
Thanks in advance for the advice...In reply to Massive Sorting by The Mage
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |