【发布时间】:2017-12-31 02:11:13
【问题描述】:
我目前正在使用 API,并且我编写了一个简短的脚本来获取我创建的项目的详细信息。我可以使用 Data::Dumper 成功显示全部内容,但我无法显示特定元素或将其分配给变量。 这是我的短代码:
# !/usr/bin/perl
use strict;
use warnings;
use TestLink::API;
use Data::Dumper;
my $tl=TestLink::API->new('http://127.0.0.1/testlink-1.9.16/lib/api/xmlrpc/v1/xmlrpc.php', 'a64aaa61db4e9f65d4e52745b86e3d8f');
print Dumper($tl->getProjectByName('Created_With_API'));
my %hachage = $tl->getProjectByName('Created_With_API');
这段代码显示我的信息,即:
$VAR1 = {
'prefix' => 'CWAPI',
'notes' => 'res ipsa loquiter',
'opt' => {
'inventoryEnabled' => '1',
'testPriorityEnabled' => '1',
'automationEnabled' => '1',
'requirementsEnabled' => '1'
},
'options' => 'O:8:"stdClass":4:{s:19:"requirementsEnabled";i:1;s:19:"testPriorityEnabled";i:1;s:17:"automationEnabled";i:1;s:16:"inventoryEnabled";i:1;}',
'color' => '',
'option_priority' => '0',
'issue_tracker_enabled' => '0',
'id' => '14',
'is_public' => '1',
'option_reqs' => '0',
'type' => 'project',
'api_key' => '9bc99494a418140a1a625257da91d9f855b452c05f498ac2db94cbbbb331db58',
'name' => 'Created_With_API',
'option_automation' => '0',
'reqmgr_integration_enabled' => '0',
'tc_counter' => '0',
'active' => '1'
};
但是我写的时候不能显示特定的元素
print "$hachage{id}";
我得到一个错误。我知道,我可能做错了什么,几天前我开始为这个 API 学习 Perl,肯定有一些糟糕的事情。但我只想知道我做错了什么。 感谢您对那些愿意花时间回答我的人的帮助;)
【问题讨论】:
-
"我几天前开始学习 Perl" ...此时,您应该专注于 learning Perl 而不是钻研第三方 API。