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

Here is my code
$agent->get($url); $page = $agent->content; $te = new HTML::TableExtract(); $te->parse ($page); @ts = $te->table_states; $ts = $ts[3]; #4th table on the page @table = $ts->rows; for $row ( @table[1..$#table] ) { if ( exists $row->[7] ) { print $row->[7]->as_text; } }
I only want to print $row->[7]->as_text if such a cell exists in the table. I tried exists to check for this, but that does not work. How could I make that if statement work?

Replies are listed 'Best First'.
Re: How to check if an array element reference exists or not
by Anonymous Monk on Apr 14, 2010 at 08:38 UTC
      I tried both those cases, but they always return false and the print statement never gets executed, even when such a cell exists.

        So, how do you determine that "such a cell exists"? I recommend printing your data structure:

        use Data::Dumper; print Dumper $row;

        That will show you whether such a cell exists in $row. Maybe it's the 7th cell, which would be at $row->[6]. Usually, when Perl says that defined $row->[7] is false, Perl is right.