linux - Perl - 伪哈希已被弃用

标签 linux perl api perl-module

我正在尝试通过 perl 获取 d 请求。但我遇到了以下错误:

#!/usr/bin/perl
use lib "/usr/packages/perl/perl-5.16.3/lib/5.16.3";
use strict;
use warnings;
use LWP::UserAgent;
use JSON;
use MIME::Base64;

my $url = 'https://example.com:8443/cli/agentCLI';
my $credentials = encode_base64('username:password');

my $ua = LWP::UserAgent->new(ssl_opts =>{ verify_hostname => 0});
my $response = $ua->get($url, 'Authorization' =>" Basic $credentials");

die 'http status: ' . $response->code . '  ' . $response->message
unless ($response->is_success);

my $json_obj = JSON->new->utf8->decode($response->content);

# the number of rows returned will be in the 'rowCount' propery
print $json_obj->{rowCount} . " rows:n";

# and the rows array will be in the 'rows' property.
foreach my $row(@{$json_obj->{rows}}){
    #Results from this particular query have a "Key" and a "Value"
    print $row->{Key} . ":" . $row->{Value} . "n";
 }

输出(错误):

agent.pl 第 21 行已弃用伪哈希。 agent.pl 第 21 行没有这样的伪哈希字段“rowCount”。

谢谢, 卡莱亚拉桑

最佳答案

参见:

http://perldoc.perl.org/5.8.8/perlref.html#Pseudo-hashes%3A-Using-an-array-as-a-hash

在最新版本中:http://perldoc.perl.org/perlref.html#Pseudo-hashes%3a-Using-an-array-as-a-hash

这已被弃用。我可以想象(但没有你的 JSON 就无法判断)你的 JSON 顶层是一个数组。

Data::Dumper 可以帮助您了解实际的数据结构是什么。

关于linux - Perl - 伪哈希已被弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28930170/

相关文章:

c - 空堆竞技场的开销

c++ - 如何在c++中直接使用addr2line

mysql - 如果 DBI::mysql_enable_utf8 未正确设置会发生什么情况?

node.js - 安全解耦后端和前端(node.js 服务器)

django - 可以使用spotify API让每个人都听一首歌吗?

linux - 我的 Makefile 中的 Bash 命令 ID 不起作用

Linux:获取文件和目录列表以及 MIME 信息

perl - 如何在 Perl 测试套件中并行运行一些但不是所有测试?

perl - gvim 找不到 Perl 模块

r - 使用R构建RESTful API