Hi,
I have a flat file which has 90000 records - one per line - and the processing time is quite lengthy. (File size is almost 10 mb)
I decided to remove the "new line" so it would minimize the number of lines and also the size of the file; size is now 3.5 mb.
Even after changing the data structure, it takes almost 5-6 full seconds to loop around the data.
Question: So I change the data structure ? So I convert the data to an hash and then loop trough the hash to do the comparison ? Your input and expertise would be appreciated.
Data Structure:
OLD:
New:
Code to process new data structure:
I have a flat file which has 90000 records - one per line - and the processing time is quite lengthy. (File size is almost 10 mb)
I decided to remove the "new line" so it would minimize the number of lines and also the size of the file; size is now 3.5 mb.
Even after changing the data structure, it takes almost 5-6 full seconds to loop around the data.
Question: So I change the data structure ? So I convert the data to an hash and then loop trough the hash to do the comparison ? Your input and expertise would be appreciated.
Data Structure:
OLD:
Code:
93993|AD003|IBG0034591
93994|AB010|IBG0105789
93995|DE012|IBG0124585
93996|EF123|IBG1237833
New:
Code:
93993|AD003|IBG0034591?93994|AB010|IBG0105789?93995|DE012|IBG0124585?93996|EF123|IBG1237833
Code to process new data structure:
Code:
sub GetData {
open(FILE,"$File") || die "Could not open $File";
my @Array = <FILE>;
close(FILE);
foreach my $Record (@Array) {
my @DataSets = split(/\?/,$Record);
foreach my $DataSet (@DataSets) {
my ($ID, $REF_NUMBER, $SEC_NUMBER) = split(/\|/,$DataSet);
if ($ID eq $InputID) {
$Value = $REF_NUMBER;
}
}
}
return $Value
}