in reply to How do I extract all text around a keyword between two symbols?

To do this reliably (assuming that's a real-life example up there), you are going to need to use some derivative of HTML::Parser--probably HTML::TokeParser, (which is recommended for small jobs),or HTML::TableExtract.

If you really are getting things out of table rows, then of course HTML::TableExtract is an easy call, and it's an easy module to use, and you're set. If a more general HTML solution is needed, then I would recommend something along the lines of the following pseudocode (using TokeParser):

my ($temp,$flag); while ($token = $parser->get_token) { if ($token eq $start_token) { $flag = 1 } elsif ($token eq $end_token) { $flag = 0; return $temp if $temp =~/KEY/; $temp = ''; } $temp .= $token if $flag; }
Please note that this is NOT correct syntax for HTML::TokeParser (though it's not as far off as I was originally expecting it to be), it's just an approximation from which (hopefully) you can figure out how to do what you want to do.



If God had meant us to fly, he would *never* have given us the railroads.
    --Michael Flanders

  • Comment on Re: How do I extract all text around a keyword between two symbols?
  • Download Code