T
torque
I have a nested foreach loop and this is really killing the
performance. The inner foreach is using the value from the outer loop
to check if it is a valid value by comparing it against an array of
valid values. I removed the inner foreach to eliminate validation and
the performance improved from 12 hours to 3 hours for 7 million
records.
But I would like to have this validation check done by the inner
foreach loop.
This is how the code looks like. Its fairly simple but I am new to
perl.
open(WVHFILE, "<file.txt");
while (<WVHFILE>)
{
chomp;
($id, $pk, $an, $eid, $vv, $val, $et) = split(/\|/);
my @token = split(";", $val);
my %rst = ();
my $flg = 0;
my $ed = substr($et,0,11);
foreach $nvpair (@token)
{
$flg = 0;
my ( $attr_id, $attr_val) = split ("=", $nvpair);
foreach $aid (@attr_lst){
if ($attr_id == $aid){
$flg = 1;
}
}
if ($flg == 1) {
$rst{$attr_id} = $attr_val . "|" . $lst{$attr_id .
$attr_val}. "|";
}
}
Please send me an alternative if you know it. I would appreciate it.
Thanks.
performance. The inner foreach is using the value from the outer loop
to check if it is a valid value by comparing it against an array of
valid values. I removed the inner foreach to eliminate validation and
the performance improved from 12 hours to 3 hours for 7 million
records.
But I would like to have this validation check done by the inner
foreach loop.
This is how the code looks like. Its fairly simple but I am new to
perl.
open(WVHFILE, "<file.txt");
while (<WVHFILE>)
{
chomp;
($id, $pk, $an, $eid, $vv, $val, $et) = split(/\|/);
my @token = split(";", $val);
my %rst = ();
my $flg = 0;
my $ed = substr($et,0,11);
foreach $nvpair (@token)
{
$flg = 0;
my ( $attr_id, $attr_val) = split ("=", $nvpair);
foreach $aid (@attr_lst){
if ($attr_id == $aid){
$flg = 1;
}
}
if ($flg == 1) {
$rst{$attr_id} = $attr_val . "|" . $lst{$attr_id .
$attr_val}. "|";
}
}
Please send me an alternative if you know it. I would appreciate it.
Thanks.