Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys.

I'm having a problem and seek advice. I'm scanning the below HTMl

<td><img class="res" src="img/un/r/1.gif" title="Lumber"></td> <td id=l4 title=60>63/1200</td> <td class="s7"> <img class="res" src="img/un/r/2.gif" title="Clay"></t +d> <td id=l3 title=60>97/1200</td> <td class="s7"> <img class="res" src="img/un/r/3.gif" title="Iron"></t +d> <td id=l2 title=60>61/1200</td><td class="s7"> <img class="res" src="i +mg/un/r/4.gif" title="Crop"></td> <td id=l1 title=43>106/1200</td>
All I need are the ##/## sets and they always appear in the same order (different numbers), so I figure I can ignore all the html and just match the (\d+\\d+).

I'm trying to break them into $lumber, $clay, $iron and $crop (in top-down order).

Can someone give me a hand?

Replies are listed 'Best First'.
Re: multi match regex
by GrandFather (Saint) on Sep 19, 2007 at 04:06 UTC
    use strict; use warnings; my $str = <<'HTML'; <td><img class="res" src="img/un/r/1.gif" title="Lumber"></td> <td id=l4 title=60>63/1200</td> <td class="s7"> <img class="res" src="img/un/r/2.gif" title="Clay"></t +d> <td id=l3 title=60>97/1200</td> <td class="s7"> <img class="res" src="img/un/r/3.gif" title="Iron"></t +d> <td id=l2 title=60>61/1200</td><td class="s7"> <img class="res" src="i +mg/un/r/4.gif" title="Crop"></td> <td id=l1 title=43>106/1200</td> HTML my @matches = $str =~ m!\d+/\d+!g; print join "\n", @matches;

    Prints:

    63/1200 97/1200 61/1200 106/1200

    using your regex with \d+\\d+ corrected to \d+/\d+.


    DWIM is Perl's answer to Gödel