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";

In reply to Re: Problem Parsing with HTML::TableExtract by Fang
in thread Problem Parsing with HTML::TableExtract by monkfan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.