sub finder { @text = ""; $wordMatchFilePosition; $number = 0; $currentFilePosition; $lastPushed = space; $tagCount = 0; $quoteCount = 0; $loopcount = 0; if (!-d $File::Find::name) { open FILEHANDLE, "<$File::Find::name"; $size = -s $File::Find::name; $_ = ''; read FILEHANDLE, $_, $size; #on our first match, store the text behind and after the #word so the user can see a short desciption of why the #word appeared $file = $File::Find::name; if(!excludedDirectory()) { if(m/$key/i) { $wordMatchFilePosition = tell FILEHANDLE; seek FILEHANDLE, -1700, 1; $currentFilePosition = tell FILEHANDLE; for($loopcount = 0; $loopcount < 3000 && $currentFilePosition != $wordMatchFilePosition+700; $loopcount++) { $tempText = getc FILEHANDLE; #if we find the begining of the tag, increment the counter #dont add the text until we are back to 0 on the counter #(meaning were not in HTML commands) if($tempText eq "<") { $tagCount++; } #because were moving back an arbitrary number of characters, #we might land in the middle of an HTML statement, therefore #if we hit a closing tag without having a begining tag #it should be safe to just ignore it elsif($tempText eq ">" && $tagCount > 0) { $tagCount--; } #More filtering of HTML elsif($tempText eq " \" ") { if($quoteCount == 1) { $quoteCount = 0; } else { $quoteCount = 1; } } #make sure were not reading HTML commands, the thing were getting #is comprised of only letters, and were not trying to read at the end #of the file, if its a space, and the last thing we pushed on the text #was a letter, then its safe to assume that was the end of a word #we are also filtering out numbers, because they are used more with #defining pages then the actual content, we also dont want things with _ #in it because its used for naming frames elsif($tagCount == 0 && $quoteCount == 0 && !eof FILEHANDLE && $tempText =~ /(\b[A-Za-z]+\b)/ || $tempText =~ /^\s/ && $tempText ne "_") { if($lastPushed eq "character" && $tempText =~ /^\s/) { push(@text," "); $lastPushed = "space"; } else { push(@text,$tempText); $currentFilePosition++; $lastPushed = "character"; } } } print @text; print "\n"; } $number++ while/^${key}/g; close FILEHANDLE; $file = $File::Find::name; $length = length ($base_address) + 1; $file =~ /^.{${length}}(.*)/; if ($number) {$hash{$1} = $number} }#end if(!excludedDirectory()) } }