Date sent:              Wed, 27 May 2009 16:50:41 +0800
Subject:                Pattern match question
From:                   Á÷Ë(R)`Oô <[email protected]>
To:                     [email protected]

> Hi, All:
>
> I want to parse data from a HTML page, data like:
>
> <tr >
>
>                       <td valign="top">
>                               YEMEN
>                       </td>
> <snipped>
> =====================================
> I want to match one <tr>...</tr> pair.
>
> my code :
>
> my $pattern = "(<tr (.|\\n)*<\\\/tr>)";
> my $match;
> while($data =~ /$pattern/g){   # $data has the content above
>    $match = $&;
>    print $match;
> }
>
> but I got the whole matches instead of one <tr>...</tr> pair each loop.
>
> Do you guys have any ideas?

Yes. Do not do that. There are modules for this kind of things.
Parsing HTML is not as simple as you seem to think.

In this case you want HTML::TableExtractor.

Or maybe HTML::Parser.

Jenda
===== [email protected] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to