in reply to Please review simple code to extract lines from a webpage description

Well, hmmm... There are a couple levels of this problem to deal with. First, if you "use strict", a number of slip-ups appear in your code. I lost track of them, but here is a tidied-up version:
use strict; use CGI; use WWW::Search; my $q = new CGI; my $search = new WWW::Search ('AltaVista'); $search->maximum_to_retrieve(10); #my $word = $q->param('query'); my $word = 'penguin'; # for testing chomp($word); $search->native_query (WWW::Search::escape_query($word)); do_print($q, $search); sub do_print { my ($q, $search) = @_; print $q->header; print $q->start_html("Web Search"); print $q->h1({-align=>"center"},'Web Concordance Search Results'); print $q->h3({-align=>"center"},"for search term '$word'"); print $q->h4({-align=>"center"},"Producing output....\n"); print $q->hr; my $n = 0; while ( my $result = $search->next_result() ) { $n++; print $q->a({href=>$result->url}, $result->url); my $urlresult = $result->url; #my $result->description = @desc; my @desc = $result->description; my $desc = "@desc"; #To strip HTML tags crudely $desc = ~s(<[^>]*>)()g; my @splittext = split(/$word/,$desc); #To extract concordance lines from text for (my $i=1; $i < @splittext; $i++) { my $before = substr((' 'x10).$splittext[$i-1],-20,20); my $after = substr($splittext[$i].' 'x10,0,20); print p($before, strong($word), $after,"\n"), } print $q->br, $result->title, "\n"; print $q->br, $result->description,"\n"; print $result->change_date,"\n"; print $q->hr; } if ($n == 0) { print "<P>Results not found"; } print qq{<P><A HREF="http://mogana/index.htm">Search Again!</A>}; print $q->end_html; }
This runs (which is nice). Unfortunately it does not return any results for display. Since there were no results to process, I left your un-Perlish 'for' loop and some of the processing in that region of the code alone for now.

So we go through the docs looking for a simple example to try and end up with:

use strict; use WWW::Search; my $Search = new WWW::Search(); $Search->native_query(WWW::Search::escape_query('penguin')); while (my $Result = $Search->next_result()) { print $Result->url, "\n"; }
Which also runs and returns no results. Drat!

Curiously, in all the docs for this module, there seems to be no example I can find of what constitutes a proper argument for WWW::Search::escape_query( . . . ). I tried several things and nothing seemed to work. And I can't find anything here on PerlMonks or on the web.

So there we are... until someone else comes along who has some experience with this module, the script runs fine and appears quite harmless! ;-)