# 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 = ; my @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++; } }