use LWP::UserAgent; use HTTP::Request; use HTTP::Request::Common; my @junk=qw(what's what i need want how to can do does has the had should will anyone help me did for please hey); my $request="@ARGV"; my $original_request= "@ARGV"; my @monkurls; my %responses; my $responsecount; # strip out crap words. foreach (@junk) { $request=~s/\b$_\b//ig}; # # arrayify the request. # if there's only one word, bail. # my @requestwords = split/ /,$request; if (scalar(@requestwords)==1){print "You expect me to search on that? No way. Maybe with some more useful words."; exit} # # start the request. # my $ua = LWP::UserAgent->new; my $url = "http://www.perlmonks.com/index.pl?node_id=864;node=$request"; my $response = $ua->request(GET $url); # # if the title is 'not found' then there's no matches. # if the title matches $request exactly, there's a node with the exact title. # return that. # if ($response->content!~m/(search results)<\/title>/i) { if ($response->content=~m/<title>(not found)<\/title>/i) { print "I couldn't find any nodes about $request. Sorry, eh?."; exit; } if ($response->content=~m/<title>($original_request)<\/title>/i) { print "I found but one node that matched your request : \"http://www.perlmonks.com/index.pl?node=$request\" may help you understand $request\n"; exit; } } my @text=split /\n/, $response->content; while ($text[0] !~ /here's the stuff:/i) {shift @text} shift @text; my $thisline = shift @text; while ($thisline !~ /<FORM METHOD=GET ACTION="http:\/\/search.cpan.org\/search">/i){ if ($thisline=~m/(<title>(.*)<\/title>)/i) { print "$1\n"; } $thisline =~ s/<LI>//; if ($thisline !~ />re:/i) { $countgrep=grep{$thisline =~/$_/i }@requestwords; if ($countgrep) { $responsecount++; $responses{$thisline}=$countgrep;#urls, %{line=>$thisline, confidence=>$countgrep}; } } $thisline = shift @text; } ; @monkurls = sort {$responses{$a} <=> $responses{$b}} keys %responses; my $index = rand @monkurls; my $quip = $monkurls[rand @monkurls]; print "Out of ". scalar@monkurls . " possibilities\n"; print "I think this url : \"$monkurls[-1]\" may best help you understand @ARGV\n. "; scalar@monkurls > 1 && print "You may also try this random hit : \"$quip\"";