Perl 获取散列的内容时出错

Perl 获取散列的内容时出错,perl,hash,Perl,Hash,我的perl代码如下所示: my $ns = scraper { process "table.table tr>td>a", 'files[]' => 'TEXT'; }; my $mres = $ns->scrape(URI->new($purlToScrape)); if ( ($#{$mres->{files}}) > 0 ) { print Dumper($mres->{files} );

我的perl代码如下所示:

my $ns = scraper {
    process "table.table tr>td>a", 'files[]' => 'TEXT';     
};
my $mres = $ns->scrape(URI->new($purlToScrape));
if ( ($#{$mres->{files}}) > 0 ) {       
    print Dumper($mres->{files} );
    foreach my $key (keys %{ $mres->{files} }) {
        print @{$mres->{files}}[$key]."\n"; 
    }
}
运行时:

$VAR1 = [
  'Metropolis (1927)',
  'The Adventures of Robin Hood (1938)',
  'King Kong (1933)',
  'The Treasure of the Sierra Madre (1948)',
  'Up (2009)',
  'Lawrence of Arabia (1962)',
];
Not a HASH reference at /root/bash-advanced-scripts/rotten.pl line 28.
第28行是这样的:

print @{$mres->{files}}[$key]."\n";

如何修复此问题?

错误来自前一行:

foreach my $key (keys %{ $mres->{files} })
$mres->{files}
是一个数组引用,因此不能将其作为哈希解引用

只用

for my $file (@{ $mres->{files} }) {
    print $file, "\n";
}

错误来自上一行:

foreach my $key (keys %{ $mres->{files} })
$mres->{files}
是一个数组引用,因此不能将其作为哈希解引用

只用

for my $file (@{ $mres->{files} }) {
    print $file, "\n";
}

您使用什么模块?
Dumper
向您显示
$mres->{files}
是数组引用。您使用什么模块?
Dumper
向您显示
$mres->{files}
是数组引用。