I've looked and looked at your code, read the parent node and your
other one and I'm not quite sure what you're actually trying to do. Still I think that you would be better off replacing the above code with the following:
# Attempt to lock only $data_dir/search.idx, if allowed
if ($file_locking ne "No")
{
flock (SIDX, LOCK_SH) or die "Can't set lock for ".
"file: $data_dir/search.idx: $!";
}
# Read whole files in to arrays. This is a really bad
# thing to do if the files are potentially huge. If
# they are small (< 1000 lines), however this is okay.
my @sidx = <SIDX>;
my @sidx2 = <SIDX2>;
# Closing filehandles removes the locks
close (SIDX);
close (SIDX2);
# Make sure that the search files have the same lengths (I'm
# guessing here, perhaps this isn't important to you).
unless(@sidx = @sidx2) {
die "Search files are of differing lengths.";
}
# Remove empty strings from @skeyw and @premiumkeyw
@skeyw = grep {$_ ne ""} @skeyw;
@premiumkeyw = grep {$_ ne ""} @premiumkeyw;
# Build a big regular expression out of @skeyw and
# @premiumkeyw for faster matching.
my $regexp = join('|', @skeyw, @premiumkeyw);
$regexp = qr/$regexp/;
foreach my $line (@sidx) {
my $premiumline = unshift(@sidx2); # destructive.
# In the previous code you write:
# $sline = $line, $premiumline;
# this is the same as:
# $sline = $line;
# I'm going to guess that you mean the following:
$sline = "$line, $premiumline";
# Do our test to see if this matches our regexp
if($sline =~ /$regexp/) {
# do something with search results
$resultline[$icnt] = $line;
$icnt++;
}
}
That should provide the same results as your code but faster and maybe more flexibly.
Hope this helps
jarich
Update: Fixed rather embarrassingly wrong use of != instead of ne in grep.
Also changed pop to unshift so elements come through in the same order.