【发布时间】:2018-01-23 16:26:39
【问题描述】:
以下 perl 脚本应将 json 转换为 csv
#!/usr/bin/perl
use strict;
use warnings;
use JSON;
my $file = 'players.json';
open( my $input, "<", $file ) or die $!;
my $json_data = decode_json(
do { local $/; <$input> }
);
foreach my $player_id ( keys %{$json_data} ) {
foreach my $fixture (
@{ $json_data->{$player_id}->{fixture_history}->{all} } )
{
print join( ",",
$player_id, $json_data->{$player_id}->{web_name},
@{$fixture}, "\n", );
}
}
json 文件在 /tmp 文件夹下 - player.json
ls /tmp | grep players.json
players.json
当我在 /tmp 下运行脚本时,我得到:
./jsonTOcsv.pl
Not a HASH reference at ./uri.pl line 15, <$input> line 1.
请指教这里出了什么问题?
【问题讨论】:
-
基本上你期待一个散列数组的散列......结构,但它似乎不是。
-
那么这里有什么问题?