【问题标题】:Retrieving Data::Dumper elements检索 Data::Dumper 元素
【发布时间】:2012-01-07 02:30:37
【问题描述】:

我正在使用 Data::Dumper 通过 SOAP 消息从服务器检索信息,并且需要一些帮助来分配返回值以进行处理。我的代码是:

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";

{device} 可以包含任意数量的元素,因此不是调用 $devices->[0],[1] 等 - 是否可以吐出所有返回的设备?我试过 $_ 和 @_ 但没有运气,因为它只返回第一个设备。

感谢任何帮助。

谢谢

【问题讨论】:

标签: perl soap data-dumper


【解决方案1】:

你是说

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

或者更简洁

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

【讨论】:

  • 或者更简洁的say for @$devices; :)
  • 感谢大家的帮助。出于某种原因,第一个建议对我不起作用,但第二个建议对我有用,而且它更容易使用。 '珍惜它!
猜你喜欢
  • 1970-01-01
  • 2012-06-06
  • 1970-01-01
  • 1970-01-01
  • 2011-06-26
  • 2014-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多