Hi, I have written a simple code on extraction of lines from the webpage description. Pls look at my codes ..does it make any sense ?? Anyway, I can't run it and pls help me to troubleshoot. I'm still a beginner and quite *dump* on it this.Feel free to give ur comments and suggestions. Thanks in advance..looking forward for some reply a.s.a.p
#!/usr/bin/perl -w require WWW::Search; use CGI; $q = new CGI; $word = $q->param('query'); chomp($word); my $search = new WWW::Search ('AltaVista'); $search->maximum_to_retrieve(10); $search->native_query (WWW::Search::escape_query($word)); &do_print; #Subroutine to print search results sub do_print { 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; while ( $results = $search->next_result()) { $n++; print $q->a({href=>$results->url}, $results->url); $urlresult = $result->url; $result->description = @desc; $desc = "@desc"; #To strip HTML tags crudely $desc = ~s(<[^>*>)()g; @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,2 +0); my $after = substr($splittext[$i].' 'x10,0,20); print p($before, strong($word), $after,"\n"), } print $q->br; print $results->title,"\n"; print $q->br; print $results->description,"\n"; print $results->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; 1; }
Rgds,

Edit kudra, 2001-10-24 Changed title


In reply to Please review simple code to extract lines from a webpage description by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.