我完全把这个问题弄错了。我正在使用 TMDB 的方法:
my @results = $search->find(id => 'tt0114694', source => 'imdb_id');
我认为输出是 JSON 格式,所以这让我很困惑,这让我一直在转圈,因为我看错了。
没有意识到下面来自 Dumper 的数据是我必须经过的实际哈希值。
这是我碰壁的地方,所以下面的数据是一个有五个键的哈希。我想要的第五个键包含另一个数组。这是我无法读入的数组。我尝试将其取消引用到哈希中,这就是我失败的地方。
我正在尝试的代码是:
foreach my $narray (@results){
print $narray->{"movie_results"};
my @newarray = $narray->{"movie_results"};
foreach my $otherarray (@newarray){
my %innerhash = $otherarray;
print %innerhash;
print "\n";
}
}
它会打印出一个数组,但我无法读取该数组中的哈希值。
ps 我必须将此输出格式化为代码,否则输出时没有换行符。
$VAR1 = {
'tv_season_results' => [],
'tv_results' => [],
'person_results' => [],
'tv_episode_results' => [],
'movie_results' => [
{
'adult' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ),
'vote_average' => '6.8',
'original_title' => 'Tommy Boy',
'vote_count' => 635,
'id' => 11381,
'release_date' => '1995-03-31',
'overview' => 'Party animal Tommy Callahan is a few cans short of a six-pack. But when the family business starts tanking, it\'s up to Tommy and number-cruncher Richard Hayden to save the day.',
'genre_ids' => [
35
],
'title' => 'Tommy Boy',
'video' => $VAR1->{'movie_results'}[0]{'adult'},
'poster_path' => '/g32WbO9nbY5ydpux5hIoiJkLEQi.jpg',
'original_language' => 'en',
'backdrop_path' => '/bZ4diYf7oyDVaRYeWG42Oify2mB.jpg',
'popularity' => '13.945'
}
]
};