in reply to Re: Searches
in thread Searches

New and improved version...
#!/usr/bin/perl -w #web_search -- a program to simulate how site index the 'Net #invocation: <web_search *.pl> to index all the *.pl files in the curr +ent directory use strict; my %words; ### Index the files undef $/; #file slurp mode for my $name (@ARGV) { open F,"<$name" or die "couldn't open $name\n"; map { push( @{$words{$_}}, $name) } split(/\s+/, <F>); #print "$_-> @{$words{$_}}\n" for keys %words; #pretty print } ### Ask for search keywords $/="\n"; #unslurp for user input print "\nEnter you list of search words: "; open I, "-"; while(<I>) { chomp; my $search_words=$_; my @tmp = split; my $intersection=pop @tmp; my @intersection=@{$words{$intersection}} if defined($words{$interse +ction}); for my $curr (@tmp) { @intersection=map {my $t=$_; $_ if grep { $t eq $_ } @{$words{$cur +r}}} @intersection; } @intersection=grep {$_} @intersection; print "\"".join(" AND ",split(/\s+/,$search_words))."\""; if (@intersection) { print " found in "; print join(", ",@intersection)."\n"; }else { print " not found\n"; } }