[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Searching help



>At 20:42 -0700 2000.08.14, Michael Eggleston wrote:
>>I need some help.  Here is the situaltion.  I have joined an entire HTML
>>document together to make it searchable using s/// and m// and now I have
>>a problem.

Just as a general tip to searching HTML docs - unless you don't mind having
th user wait while a cgi sifts through existing documents, which users
usually aren't too keen on doing, why not write a small program that sifts
through the docs on your HD and create an index file, which you then search
through, having the thing precomputed saves server overhead.

The script below will split a document up into an alphabetically ordered
list with the name of the file it came from appended to eacg word, as it
stands it has a document hard coded into it, however with a little adaption
you could use it to parse a directory and write the output.

#! perl -w

#=========== declare includes =============

use strict;
use diagnostics-verbose;

#========== declare variables =============

my($file,@words,@temp,%data);

#============= script body ================
$file='Macintosh HD:Desktop Folder:temp';
open (IN, $file);
while (<IN>) {
    s/-\n//g;                   # Dehyphenate hyphenations spread over 2 lines.
	tr/A-Z/a-z/;            # text to L/C
	tr/\"\'\(\)\~\[\]\@\.\,\;\:\&\%\-\=//ds; #kill any non words
(punctuation,

#brackets etc.)
	tr/1234567890//ds; #kill numbers
	chomp;# Kill return chars
    @temp=split; #break input into individual words

    for (@temp) {


	$data{$_}++; #attach a counter to the word
    }
}

@words=sort(keys(%data)); #put into alphabetical order
for (@words) {

        print "$_\t $file\n" if ~!/\W*/;



}


close (IN);

__END__

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org