in reply to Problem Parsing with HTML::TableExtract
HTML::TableExtract parses that file perfectly (as always). To verify how the module sees your data, you should always try a little snippet like the one in the synopsis of the module.
#!/usr/bin/perl use strict; use warnings; use HTML::TableExtract; die 'Missing argument!' unless (@ARGV); my $file = shift @ARGV; my $te = HTML::TableExtract->new(); $te->parse_file($file); for my $table ($te->tables) { print 'Table (', join(', ', $table->coords), "):\n"; my $rownumber = 1; for my $row ($table->rows) { print "Row $rownumber: ", join(', ', @$row), "\n"; $rownumber++; } }
Your error comes from your my @total = @{ $all_table_content[0]->[-1] }; line. You probably got the message Not an ARRAY reference at bin/perl/tableextract.pl line 38 as I did. As you can see from the code above, you need to use the rows method. But the trick is that if you simply do @{ $all_table_content[0]->rows->[-1] }, perl will evaluate the part up to rows in scalar context and will prevent you to do so as you're using strict (and if you remove it, it won't work anyway). So you have to force list context, and take the last element of that list before dereferencing it. In perl, this means:
my @total = @{ [ $all_table_content[0]->rows ]->[-1] }; print join(', ', @total), "\n";
OK, so that's butt-ugly to me, and to any sane person I assume, but it works. So an other, more readable solution could be:
my $table = ($te->tables)[0]; my $count = $table->rows; my $last_row = $table->row($count - 1); print join(', ', @$last_row), "\n";
|
|---|