#!/usr/bin/perl -w #web_search -- a program to simulate how site index the 'Net #invocation: to index all the *.pl files in the current 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+/, ); #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() { chomp; my $search_words=$_; my @tmp = split; my $intersection=pop @tmp; my @intersection=@{$words{$intersection}} if defined($words{$intersection}); for my $curr (@tmp) { @intersection=map {my $t=$_; $_ if grep { $t eq $_ } @{$words{$curr}}} @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"; } }