bigbalbossa
Programmer
I'm doing a string compare on two variables in two different files.
File1: contains a lookup key
File2: contains the lookup key, key2, and key3 field
If the file1 key matches a key in file2, i need to append the key2 and key3 fields to file1.
My current script is working properly, but runtime is way too long due to the way i'm performing my match.
First reading file2 into and array:
Then looping through my datafile:
Any thoughts on other ways to accomplish this???
File1: contains a lookup key
File2: contains the lookup key, key2, and key3 field
If the file1 key matches a key in file2, i need to append the key2 and key3 fields to file1.
My current script is working properly, but runtime is way too long due to the way i'm performing my match.
First reading file2 into and array:
Code:
open(SAL, "$SAL_INI") || die "Can't open file: $SAL_INI\n";
while(<SAL>)
{
chomp;
my $data = $_;
( $key1[$i], $key2[$i], $key3[$i] ) = split( '\|', $data );
$i++;
}
Then looping through my datafile:
Code:
for ($n=0;$n<$i;$n++)
{
if ($KEY eq $key1[$n])
{
$search_idx = $n;
}
}
if ($search_idx != -1)
{
#print "SAL match\n";
$KEY2 = "$key2[$search_idx]";
$KEY3 = "$key3[$search_idx]";
}
else
{
...
}
Any thoughts on other ways to accomplish this???