首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无福Hashref错误

无福Hashref错误
EN

Stack Overflow用户
提问于 2016-10-24 02:44:31
回答 1查看 298关注 0票数 2

我一直在学习驼鹿,并且在测试中挣扎,我不断收到错误信息。

代码语言:javascript
复制
Type of argument to keys on reference must be unblessed hashref or arrayref at ./GO2.t line 40, <DATA> chunk 1.

我已经包含了我的.t脚本,我不知道如何修复这个错误,也没有找到任何答案,确切地说是一个不受祝福的hashref。我没有包括数据中的所有内容,只是几次迭代。我在想我打错了哈希

代码语言:javascript
复制
#!/usr/bin/perl
use warnings;
use strict;
use GO2;
use MooseX::FollowPBP;

use Test::More tests => 44;

#Initialize $_ to prevent warnings in redefinition of $/ as RegEx
$_ = '';
local $/ = /\[Term\]|\[Typedef\]/;

while (<DATA>) {

    # Remove end-of-line characters
    chomp;

    # parse the record using a regular expression
    my $longGoDesc = $_;

    #Create a new GO object
    my $go = GO2->new( 'longGoDesc' => $longGoDesc);

    # ok is a test function that prints ok if the test is true, and
    ok( defined $go->get_id() );
    ok( defined $go->get_def() );
    ok( defined $go->get_name() );
    ok( defined $go->get_namespace() );

    # Initialize is_a counter
    my $isaCount = 0;

    #Loop through the is_a array reference
    foreach my $isaRef ( keys $go->{is_as} ) {
 #Make sure the is_a is defined
            ok( $go->get_is_as()->[$isaRef] );

            #Increment is_a counter
            $isaCount++;
    }

    #Make sure at least one is_a
    ok( $isaCount > 0 );

    # Initialize alt_id counter
    my $altIdCount = 0;

    # Check for alt_id
#       if ( defined $go->{alt_ids} ) {

            #Loop through is_a
            foreach my $altIdRef ( keys $go->{alt_ids} ) {
                    ok( $go->get_alt_ids()->[$altIdRef] );

                    # Increment alt_id counter
                    $altIdCount++;


    }

    #Make sure at least one alt_id
    ok( $altIdCount > 0 );
}

# Indicate that tests are done
done_testing();

# Everything below __END__ is treated as input for the DATA filehandle.
 __END__
[Term]
id: GO:2001315
name: UDP-4-deoxy-4-formamido-beta-L-arabinopyranose biosynthetic process
namespace: biological_process
alt_id: GO:0019901
def: "The chemical reactions and pathways resulting in the formation of a UDP-4-deoxy-4-formamido-beta-L-arabinopyranose." [CHEBI:47027, GOC:yaf, UniPathway:UPA00032]
synonym: "UDP-4-deoxy-4-formamido-beta-L-arabinopyranose anabolism" EXACT [GOC:obol]
synonym: "UDP-4-deoxy-4-formamido-beta-L-arabinopyranose biosynthesis" EXACT [GOC:obol]
synonym: "UDP-4-deoxy-4-formamido-beta-L-arabinopyranose formation" EXACT [GOC:obol]
synonym: "UDP-4-deoxy-4-formamido-beta-L-arabinopyranose synthesis" EXACT [GOC:obol]
is_a: GO:0009226 ! nucleotide-sugar biosynthetic process
is_a: GO:0046349 ! amino sugar biosynthetic process
is_a: GO:2001313 ! UDP-4-deoxy-4-formamido-beta-L-arabinopyranose metabolic process

[Term]
id: GO:2001316
name: kojic acid metabolic process
namespace: biological_process
alt_id: GO:0019902
def: "The chemical reactions and pathways involving kojic acid." [CHEBI:43572, GOC:di]
synonym: "5-hydroxy-2-(hydroxymethyl)-4H-pyran-4-one metabolic process" EXACT [CHEBI:43572, GOC:obol]
synonym: "5-hydroxy-2-(hydroxymethyl)-4H-pyran-4-one metabolism" EXACT [CHEBI:43572, GOC:obol]
synonym: "C6H6O4 metabolic process" RELATED [CHEBI:43572, GOC:obol]
synonym: "C6H6O4 metabolism" RELATED [CHEBI:43572, GOC:obol]
synonym: "kojic acid metabolism" EXACT [GOC:obol]
is_a: GO:0034308 ! primary alcohol metabolic process
is_a: GO:0042180 ! cellular ketone metabolic process
is_a: GO:0046483 ! heterocycle metabolic process
is_a: GO:1901360 ! organic cyclic compound metabolic process

[Term]
id: GO:2001317
name: kojic acid biosynthetic process
namespace: biological_process
alt_id: GO:0019903
def: "The chemical reactions and pathways resulting in the formation of kojic acid." [CHEBI:43572, GOC:di]
synonym: "5-hydroxy-2-(hydroxymethyl)-4H-pyran-4-one anabolism" EXACT [CHEBI:43572, GOC:obol]
synonym: "5-hydroxy-2-(hydroxymethyl)-4H-pyran-4-one biosynthesis" EXACT [CHEBI:43572, GOC:obol]
synonym: "5-hydroxy-2-(hydroxymethyl)-4H-pyran-4-one biosynthetic process" EXACT [CHEBI:43572, GOC:obol]
synonym: "5-hydroxy-2-(hydroxymethyl)-4H-pyran-4-one formation" EXACT [CHEBI:43572, GOC:obol]
synonym: "5-hydroxy-2-(hydroxymethyl)-4H-pyran-4-one synthesis" EXACT [CHEBI:43572, GOC:obol]
synonym: "C6H6O4 anabolism" RELATED [CHEBI:43572, GOC:obol]
synonym: "C6H6O4 biosynthesis" RELATED [CHEBI:43572, GOC:obol]
synonym: "C6H6O4 biosynthetic process" RELATED [CHEBI:43572, GOC:obol]
synonym: "C6H6O4 formation" RELATED [CHEBI:43572, GOC:obol]
synonym: "C6H6O4 synthesis" RELATED [CHEBI:43572, GOC:obol]
synonym: "kojic acid anabolism" EXACT [GOC:obol]
synonym: "kojic acid biosynthesis" EXACT [GOC:obol]
synonym: "kojic acid formation" EXACT [GOC:obol]
synonym: "kojic acid synthesis" EXACT [GOC:obol]
is_a: GO:0018130 ! heterocycle biosynthetic process
is_a: GO:0034309 ! primary alcohol biosynthetic process
is_a: GO:0042181 ! ketone biosynthetic process
is_a: GO:1901362 ! organic cyclic compound biosynthetic process
is_a: GO:2001316 ! kojic acid metabolic process
synonym: "Roundabout signalling pathway involved in muscle cell chemotaxis toward tendon cell" EXACT [GOC:obol]
synonym: "Roundabout signalling pathway involved in muscle cell chemotaxis towards tendon cell" EXACT [GOC:obol]
is_a: GO:0035385 ! Roundabout signaling pathway
relationship: part_of GO:0036061 ! muscle cell chemotaxis toward tendon cell

[Term]
id: GO:2001284
name: regulation of BMP secretion
namespace: biological_process
alt_id: GO:0019904
def: "Any process that modulates the frequency, rate or extent of BMP secretion." [GOC:sart]
synonym: "regulation of BMP protein secretion" EXACT [GOC:obol]
synonym: "regulation of bone morphogenetic protein secretion" EXACT [GOC:obol]
is_a: GO:0010646 ! regulation of cell communication
is_a: GO:0023051 ! regulation of signaling
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-24 06:12:23

keys($ref)是一个已经被放弃的实验特性。你不应该用它。必须将散列(keys(%...))或数组(keys(@...))传递给keys

要获取引用数组的键,请执行以下操作:

代码语言:javascript
复制
keys(@{ $ref })

或者简单地说:

代码语言:javascript
复制
0 .. $#{ $ref }

当然,存在访问对象内部的问题。您的代码可能应该是:

代码语言:javascript
复制
my $is_as_s = $go->get_is_as();
my $isaCount = @$is_as_s;

for my $is_as ( @$is_as_s ) {
   ok($is_as);
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40210008

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档