这是我的temp.html
<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
我正在尝试使用以下代码打印上表中的每个元素 -
#!/usr/bin/perl
use strict;
use Data::Dumper;
use HTML::TableExtract;
my $tex = HTML::TableExtract->new(keep_html=>1);
$tex->parse_file('./temp.html');
my ($table) = $tex->tables;
#print Dumper($table);
my $numColumns = @{$table->rows->[0]};
print "\n numColumns = $numColumns\n";
my $numRows = @{$table->rows};
print "\n numRows = $numRows\n";
for my $rowIndex ( 0..$numRows-1 ) {
for my $columnIndex ( 0..$numColumns-1 ) {
print "\n row $rowIndex column $columnIndex $table->rows->[$rowIndex][$columnIndex] ";
}
}
它打印 -
row 0 column 0 HTML::TableExtract::Table=HASH(0x8e7d7f8)->rows->[0][0]
row 0 column 1 HTML::TableExtract::Table=HASH(0x8e7d7f8)->rows->[0][1]
row 1 column 0 HTML::TableExtract::Table=HASH(0x8e7d7f8)->rows->[1][0]
row 1 column 1 HTML::TableExtract::Table=HASH(0x8e7d7f8)->rows->[1][1]
如果我使用@{$table->rows->[$rowIndex]}->[$columnIndex]
而不是$table->rows->[$rowIndex][$columnIndex]
得到正确的输出,但会出现警告。如何删除警告?
Using an array as a reference is deprecated at t.pl line 21.
row 0 column 0 row 1, cell 1
row 0 column 1 row 1, cell 2
row 1 column 0 row 2, cell 1
row 1 column 1 row 2, cell 2