Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: help shorten this series of regexes

by Anno (Deacon)
on Sep 19, 2007 at 09:20 UTC ( [id://639841]=note: print w/replies, xml ) Need Help??


in reply to help shorten this series of regexes

There is a module on CPAN, named HTML::TableExtractor or similar that should be able to help with your task.

Warnings about using regular expressions for HTML parsing aside, here is one approach that extracts data according to your pattern into a hash (named %price at a guess):

my $html = <<EOT; stuff Lumber:</td><td align="right"><b>10 more stuff Clay:</td><td align="right"><b>20 glug Iron:</td><td align="right"><b>30 blub Crop:</td><td align="right"><b>40 stuff again EOT my %price; $price{ lc $1} = $2 while $html =~ m#(\w+):</td><td align="right"><b>(\d+)#ig; my ( $lumber, $clay, $iron, $crop) = @price{ qw( lumber clay iron crop)};
Anno

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://639841]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-03-28 14:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found