in reply to Script Executes Very Slowly
I didn't bother trying to build sample data to test with, so I'm gonna make a few guesses. Perhaps one or more may be helpful.
First, in your inner loop, you're splitting out the @match array and *then* checking for a regular expression match to decide whether to print a row. I'd suggest checking with the regular expression first, modifying it a little to ensure that it stops at the tab, and capturing the data after the tab for printing, something like this:
foreach my $line (@flab) { if ($line =~ /[^\t]*\Q$sTab[1]\E\t([^\t]+)/) { print RESULT "$sTab[0]\t$sTab[1]\t$2\n"; } }
Next, if you're actually checking for an exact name, rather than using a regular expression, you could just use the eq operator. Even better, if you are checking for an exact name, then you can convert @flab into a hash, and do the lookup by the name:
while (my $sLine = <LONG_LIST>) { chomp $sLine; my ($company, $name) = split /\t/, $sLine; if (exists $flab{$name}) { print RESULT "$company\t$name\t$flab{$name}{TITLE}\n"; } }
If you *do* need to use a regular expression, then you may be better off creating a composite one from your @flab entries. That way you can reduce the number of regular expression searches you actually perform. If you also convert @flab into a hash, then you could do it (something) like:
my $tmp = join("|", keys %flab); my $regex = qr/(?:$tmp)/; while (my $sLine = <LONG_LIST>) { chomp $sLine; if ($sLine =~ $regex) { my ($company, $name) = split /\t/, $sLine; print RESULT "$company\t$name\t$flab{$name}\n"; } }
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|