in reply to Searches

#!/usr/bin/perl #web_search -- a program to simulate how sites index the 'Net. #invocation: <web_search *.pl> 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+/, <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>) { for (split) { if (defined($words{$_})) { print "$_ found in ".join(", ",@{$words{$_}})."\n"; }else { print "$_ not found\n"; } } }

Replies are listed 'Best First'.
Re: Searches
by sleepingsquirrel (Chaplain) on Dec 03, 2003 at 16:56 UTC