in reply to Getting data from HTML::TableExtract into a hash

The following should help you out for now:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use HTML::TableExtract; my $te = new HTML::TableExtract (); $te->parse ($html_string); my $name = 'bob'; my %results; foreach my $ts ($te->tables) { my ($header_row, @content_rows) = $ts->rows; my ($placeholder, @headers) = @$header_row; foreach my $data_row (@content_rows) { my( $type, @real_data ) = @$data_row; foreach my $i (0 .. $#headers) { my $hash_key = join( '_', lc($name), lc($headers[$i]), lc($t +ype) ); $results{ $hash_key } = $real_data[$i]; } } } print Dumper( \%results ); exit;
There would be probably many things to add; I'd say for now only that if you learn quickly to use Data::Dumper, that might be an tremendous help in getting a good start.

Good luck.

Replies are listed 'Best First'.
Re^2: Getting data from HTML::TableExtract into a hash
by skoney (Novice) on Oct 14, 2007 at 14:27 UTC
    Thanks for the quick response, Krambambuli! It took me a little time to see what you were doing with this code (I'm still very new at this) but now I get it. Creating the hash keys on the fly is a very elegant solution, and one that hadn't occurred to me! I was planning on starting with a pre-formed hash but I can see now there's really no need to. That's why I like coming here - so many great ideas!

    Thanks for the heads-up on Data::Dumper. I'm going to go download the POD for it and see if I can figure out how to use it.

    Thanks again!

    Tom