my @Notes; # array of PNSearch objects foreach my $file (@Files) { next unless (-f "$DBDir/$file" && !-z "$DBDir/$file"); # scan text only database # each file represents one .html page, each line represents one whole note unless (open(DB, "<$DBDir/$file")) { CGIutil->logger($Log,"!!Could not open $DBDir/$file: $!"); next; } my @lines = (); # array of arrays, 0 = line number 1 = terms found: qv. checkline() below my $ln = 1; while () { my @found = ($ln,checkline($_)); push @lines, \@found if $found[1]; $ln++; } close(DB); # pull selected notes from markup database my $cur = 0; # last line in db my $MUH; unless (open($MUH, "<$DBDir/markup/$file")) { CGIutil->logger($Log,"!!Can't open /markup/$file: $!"); next; } foreach my $l (@lines) { my $pns = PNSearch->new($MUH, $l->[0]-$cur, $l->[1], $file); push @Notes, $pns if ($pns); $cur = $l->[0]; } close($MUH); } sub checkline { my $line = pop; my $c = 0; foreach (@Terms) { $c += 1 if ($line =~ /$Pfix<\|>.*?$_/); # anchor name is before first <|> (don't search that) } # nb: return value is the number of terms found, not the number of individual hits # ie, if there is only one search term, this will be 0 or 1 return $c; }