I wrote a small script that would read a larger file and break it up into smaller files when it matched on certain characters. (these characters were the beginning of every file)
The problem is when I run it on a really huge file, like a file with a 100,000 seperate files the script really slows down. Any ideas on how to speed up the script? Would threads help?
Here is the script below, thanks for any help:
#split multiple NY/NE order files into single orders files.
#Declaring my variables
$num='0000000';
$count = 0;
$wramp='wramp';
$file='drsoap_sodata.txt';
open (FH, $file) or die "Can't open file";
while (<FH> ) {
$count++ if (/^(\d{3}\s\w{3}-\d{4}\s{5}\d|\d{3}\s\w{3}-\d{4}\w{5}\d)/);
if ($count == 1) {
$num++;
$count=0;
open NEW, "> $wramp-$num.txt" or die "could not open $wramp-$num.txt : $!";
}
print NEW;
}
close FH;
close NEW;
THANKS!!
The problem is when I run it on a really huge file, like a file with a 100,000 seperate files the script really slows down. Any ideas on how to speed up the script? Would threads help?
Here is the script below, thanks for any help:
#split multiple NY/NE order files into single orders files.
#Declaring my variables
$num='0000000';
$count = 0;
$wramp='wramp';
$file='drsoap_sodata.txt';
open (FH, $file) or die "Can't open file";
while (<FH> ) {
$count++ if (/^(\d{3}\s\w{3}-\d{4}\s{5}\d|\d{3}\s\w{3}-\d{4}\w{5}\d)/);
if ($count == 1) {
$num++;
$count=0;
open NEW, "> $wramp-$num.txt" or die "could not open $wramp-$num.txt : $!";
}
print NEW;
}
close FH;
close NEW;
THANKS!!