perl json map创建问题

时间:2014-04-01 07:33:13

标签: json perl

我是perl的新手(我几乎什么都不知道:-)) 我有一个脚本可以在我的本地计算机上运行但不在服务器上: - (

看起来像:

my $json = JSON->new;
my $json_map = [];


for (my $i = 0; $i <= $#commitlist; $i++) {
    my %co = %{$commitlist[$i]};
...

    push $json_map, {esc_html($co{'id'})=> {author=>esc_html($co{'author'}),pubDate=>$cd{'rfc2822'},link=>$co_url, title=>esc_html($co{'title'})}};


}

my $output = $json->encode($json_map);
print $output . "\n";

它有效,结果是这样的:

[{"id":{"author":"johny","title":"some title","link":"http://127.0.0.1","pubDate":"Fri, 14 Mar 2014 12:31:17 +0000"}}]

但是现在我在服务器上遇到了问题(有perl 5.8.8版本,但我想在脚本中修复它):

要推送的arg 1的类型必须是XX行XX处的数组(非私人变量),靠近“};”

1 个答案:

答案 0 :(得分:4)

当你进行推送时,你需要取消引用第一个参数(即你正在推动的数组)。像这样:

push @$json_map, ...

希望这有帮助。