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):
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.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; }
In reply to Re: How do I extract all text around a keyword between two symbols?
by ChemBoy
in thread How do I extract all text around a keyword between two symbols?
by cdherold
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |