2015-12-21 25 views
0

我们有一个用Perl编写的客户端代码,它试图连接到一个WebService来进行API调用。如何获取perl脚本中的二维数组数据?

  1. 这个API调用是用java写的,它返回一个2-Dimemsion字符串数组。
  2. 这里是客户端的代码:
 

    eval { 
      $service = SOAP::Lite->service("some WS link here"); 
    }; 
    if ($exception = [email protected]) { 
      print("Failed to connect to WS: $exception"); 
      return 0; 
    } 

    my $status; 
    eval { 
      $status = $service->getStatus(); 
    }; 
    if ($exception = [email protected]) { 
      print("$exception"); 
      return 0; 
    } 

我的问题是如何从这个“$状态”值提取的实际数据。当我打印这个“$ status”值时,我只能看到:

 

    DB> p $status 
    stringArrayArray=HASH(0x126e2ac0) 
    DB> 

回答

1

这意味着你的模块已经返回了一个散列引用。你可以看到它的内容。 Data::Dumper

或者:

foreach my $key (keys %$status) { 
    print "$key => ", $status -> {$key}, "\n"; 
} 

参见:perlref

+0

感谢您的提示。但是如果我使用Data :: Dumper,这就是我所得到的:$ VAR1 = bless({0} {0} {0} {'item'=> undef } },'stringArrayArray');这完全失去了我。 – user3595231

+0

你的API正在返回垃圾。这就是你的问题的根源 - 你有一个可以访问的嵌套散列:'$ service - > {item} - > {item}'但它是未定义的。 – Sobrique

+0

感谢您的帮助。网络服务方面存在一个小问题。并且在我将它修好之后,这里是来自翻斗车的全套数据,“$ VAR1 = { 'item'=>'0' } }; ”。但是包装中仍然没有实际的数据。我想我的问题是客户端(perl)真的可以从ws获得全套响应吗? – user3595231