Perl初學者在這裏。我正在爲我的工作爲工作流程編寫一個小型自動化腳本。我需要將一組數字作爲輸入(從JSON文件開始輸入)傳遞到我的Perl函數中。這裏是我的代碼:我想通過這個數組,但只有數字到我的Perl函數
my $idFile='GNOC_IDS.json';
my $idJSON;
{
local $/;
open my $fh, '<', $idFile or die $!;
$idJSON = <$fh>;
close $fh;
}
my $id_array = decode_json $idJSON;
my @decodedIDS = Dumper(\$id_array);
foreach my $ids(@decodedIDS){
print $ids;
my $results= $client->get_entities(
entity_id=>$ids
);
print Dumper(\$results);
}
不過,我的問題是,$ IDS具有以下格式:
[ {
'MISC' => '1743'
},
{
'MISC' => '1743'
},
{
'MISC' => '1733'
},
{
'MISC' => '2736'
},
{
'MISC' => '1763'
},
{
'MISC' => '3133'
},
{
'MISC' => '1743'
},
{
'MISC' => '1733'
},
{
'MISC' => '2802'
},
{
'MISC' => '1699'
},
{
'MISC' => '2736'
},
{
'MISC' => '2600'
}
]
我想是養活只是數字(例如1699,2735,等等)進入'get_entities'函數,因爲現在它給了我一個「輸入必須是整數唯一錯誤」。
這完美地工作,非常感謝你。剛剛起步的人,好奇心,這是什麼:$ _正好?我已經看到它經常使用。 –
不客氣。 $ _是一個特殊的變量,在'map'的鏈接中有解釋。 – toolic
[關於'$ _'的問題](http://stackoverflow.com/questions/3589837/what-is-the-significance-of-an-underscore-in-perl/3589995#3589995) – Sobrique