我目前正在使用API,并且编写了一个简短的脚本来获取我创建的项目的详细信息。我能够成功地用Data :: Dumper显示整个内容,但我无法显示特定元素或将其分配给变量。 这里是我的短代码:显示哈希{Perl}的内容
# !/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](http://shop.oreilly.com/product/0636920049517.do),而不是钻研到第三方API。 –