2012-01-07 59 views
1

我正在使用Data :: Dumper从SOAP消息传递服务器检索信息,并需要一些帮助来分配处理返回值。我的代码是:正在检索Data :: Dumper元素

my $cm = new SOAP::Lite 
encodingStyle => '', 
uri => "$axltoolkit", 
proxy => "https://$cucmip:$axl_port/axl/"; 

my $res =$cm->getUser(SOAP::Data->name('userid' => "387653")); 

unless ($res->fault) { 
    $Data::Dumper::Incident=3; 
    my($reply) = $res->paramsall(); 
    my ($devices) = $reply->{user}{associatedDevices}{device}; 
    print $devices->[0]."\n"; 
    print $devices->[1]."\n"; 
    print $devices->[2]."\n"; 

{设备}可能包含任意数量的元素,从而代替呼叫$设备 - > [0],[1],等等 - 这可能吐出所有返回装置?我试过$ _和@_,但没有运气,因为它只是返回第一个设备。

任何帮助表示赞赏。

感谢

+1

只需从http://perldoc.perl.org/perlreftut.html#Using-References – tadmc 2012-01-07 03:11:44

回答

3

你的意思是

foreach my $device (@$devices) { 
    print "$device\n"; 
} 

或者更简洁

print "$_\n" foreach @$devices; 
+1

甚至更​​简洁适用 “使用规则1”'说了@ $设备; ':) – 2012-01-07 03:24:49

+0

感谢帮助暴徒。出于某种原因,第一个建议对我来说不起作用,但第二个建议并没有用到,而且无论如何都更容易使用。 '嫉妒它! – 2012-01-07 05:08:53