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

Hi Monks,
I'm trying to parse some table content out of a HTML page and was having some trouble so I've whipped up a dummy table and script and I'm getting an error stating that I 'Can't call method "rows" on unblessed reference at ./s.pl line 25'. Here is the dummy html file...
<html> <body> <table align="center"> <tr><td>Name</td><td>Blah</td></tr> <tr><td>bill</td><td>fdagdfg</td></tr> <tr><td>ted</td><td>sdfsdf</td></tr> </table> </body> </html>

and the script....
#!/usr/bin/perl use warnings; use strict; use HTML::TableExtract; #my $te = HTML::TableExtract->new ( depth => 1, count => 2 ); my $te = HTML::TableExtract->new ( attribs => { align => 'center' } ); print "Start\n"; my $data; { local( $/, *FILE); open FILE, "blah.html" or die "Could not open file , $!\n"; $data = <FILE>; close (FILE); } print $data; $te->parse($data); print "table stuff:\n"; foreach my $ts ( $te->tables ) { print "Table\n"; foreach my $row ( $ts->rows ) { print "R ", join(',', @$row), "\n"; } }

I'm sure this is probably quite simple, but at this hour its eluding me so I was hoping someone might be able to explain what is going on.

Regards Paul

Replies are listed 'Best First'.
Re: Table::Extract unblessed reference
by GrandFather (Saint) on Jul 29, 2005 at 23:53 UTC

    tables () is depricated and should be replaced by table_states ().


    Perl is Huffman encoded by design.
      as for deprecated methods, see my comment above -- it's the other way around. table_states() is deprecated, tables() is the shortened version. Both still work at the moment.

      Matt

        I was going to quote from the current documentation to show how confusing it is. I realised that not only is the Deprecation section of the documentation confusing, but it proposes changes that are down right nasty because they involve various gratuitous breaking changes to the current interface.

        Somehow I'm not surprised that about half of those replying to OP were confused!


        Perl is Huffman encoded by design.
Re: Table::Extract unblessed reference
by johnnywang (Priest) on Jul 29, 2005 at 23:21 UTC
    $te->tables() is deprecated, you can use $te->table_states().
      Hmm, it's the other way around. table_states() and associated *_state() methods are deprecated, the shortened versions are de rigueur now.

      Matt

Re: Table::Extract unblessed reference
by kwaping (Priest) on Jul 29, 2005 at 23:18 UTC
    I wonder if this line (line 74 of the module source) has anything to do with it:
    sub new { my $that = shift; my $class = ref($that) || $that; #<-- (line 74) # [snip] bless $self, $class; }
    I've never seen a class name determined that way before. ref($that) will return the type of reference if $that is a reference. That doesn't seem right, does it? I'm thinking maybe the module author meant to use a conditional operator there instead.

      If $that is not a reference, ref returns a false value and the constructor uses the value of $that literally as the class name. In effect, you can call new() as a class or an object method and receive a new object back.

      I consider that a bad design decision, but good luck trying to convince people that, when the documentation recommends it....

        I consider that a bad design decision, but good luck trying to convince people that, when the documentation recommends it....

        Actually, I agree with this. That little snippet is an artifact from back when I wrote the original code. Since then I've changed my mind about that trick.

        Matt

Re: Table::Extract unblessed reference
by mojotoad (Monsignor) on Aug 01, 2005 at 07:00 UTC
    Hi Paul,

    What version of HTML::TableExtract are you using? I recently fixed an attribute-related extraction bug. The current version is 2.03.

    Matt

      Hi Matt,
      I asked the sys-admin of the server I'm writing some code for to install the module...should have thought of the versioning.... it turns out he installed 1.10..

      Regards Paul.
Re: Table::Extract unblessed reference
by mojotoad (Monsignor) on Aug 02, 2005 at 15:49 UTC
    Yikes!

    After conversing with Grandfather it turns out that the source of the confusion is version 1.10 of HTML::TableExtract. After clearing up my own confusion, since I was comparing 2.x version of the docs, I finally went back and looked at the 1.10 documentation. It is indeed confusing.

    Since then, of course, I've moved on to the 2.x series and the deprecations have actually taken place.

    Cheers,
    Matt