我正在嘗試使用Perl腳本連接到Footprints API。我使用Perl是因爲它是Footprints API可以使用的少數幾種語言之一。將Perl數組傳遞給bash腳本
我想這個Perl腳本從腳印採集數據,將數據在陣列中,並通過該數組回到shell腳本調用它。如何將數組從Perl腳本傳遞到bash腳本?
下面是連接到Footprints API和收集數據的模板。
模板:
use strict;
use SOAP::Lite;
my $USE_PROXY_SERVER = 1;
my $soap = new SOAP::Lite;
$soap->uri('http://fakeserver.phoneycompany.com/MRWebServices');
if ($USE_PROXY_SERVER) {
$soap->proxy(
'http://fakeserver.phoneycompany.com/MRcgi/MRWebServices.pl',
proxy => ['http' => 'http://localhost:8888/']);
}
else {
$soap->proxy('http://fakeserver.phoneycompany.com/MRcgi/MRWebServices.pl');
}
my $soapenv = $soap->MRWebServices__search(
'WebServices',
'fakepassword',
'',
"select mrID, mrTITLE from MASTER78 WHERE mrTITLE LIKE '%of%'"
);
my $result;
if ($soapenv->fault) {
print ${$soapenv->fault}{faultstring} . "\n";
exit;
}
else {
$result = $soapenv->result;
}
my @result_list = @{$result};
for (my $i = 0; $i <= $#result_list; $i++) {
print "RESULT $i\n";
my $hash_ref = $result_list[$i];
foreach my $item (keys %{$hash_ref}) {
my $val = $hash_ref->{$item};
print "$item = '$val'\n";
}
print "---------------------\n";
}
在模板中,我覺得這只是打印鍵/值對到標準輸出。
我是Perl新手,僅使用它來搜索Footprints API。我不知道你是否可以通過bash腳本以某種方式捕獲stdout中的數據,或者如果必須對數組進行數組或字符串表示並返回該數組。
在我的bash腳本,我要的Perl腳本的結果分配給一個變量像VAR=(perl perl_script.pl)
。但是我不知道如何爲數組做這件事,這就是爲什麼我正在考慮數組的字符串表示,將它分配給一個變量,然後在bash中解析它。
我不知道如何設置了在Perl的,所以我需要提供幫助的。
爲什麼要使用bash的根本,如果你有Perl的可用功率? – Borodin
只是因爲我不知道Perl和我知道猛砸,但我開始認爲它會更好地工作,如果我只是教我一些基本知識,並嘗試一下 –