2016-10-24 3 views
2

私はムースを学習されていると私のテストに苦しんでいますが、私は私.Tスクリプトを用意しましたエラーメッセージblessされていないハッシュリファレンスエラー

Type of argument to keys on reference must be unblessed hashref or arrayref at ./GO2.t line 40, <DATA> chunk 1. 

を得続ける、私はこのエラーを修正するかどうかはわかりませんまったく無二のハッシュリファレンスが何であるかについては何の答えも見つけられていません。私はDATAのすべてを含んでいませんでしたが、ほんの数回繰り返しました。 私は

#!/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 
+0

{$行く - > {is_as}} 'キー%を試してみてください - それがある場合、'、それはハッシュリファレンス、または単に '@ {> {is_as} $行く}であれば'配列参照。 – xxfelixxx

+0

'local $/=/\ [Term \] | \ [Typedef \] /;'は$ /を正規表現に設定しません。正規表現と '$ _'をマッチさせ、' $/'(真に' '1 '' '' '' '')にブール結果を代入します。 – melpomene

+0

http://perldoc.perl.org/perlreftut.html – xxfelixxx

答えて

2

keys($ref)間違ってハッシュを呼んだと思っていますが放棄されている実験的な機能でした。あなたはそれを使用すべきではありません。ハッシュ(keys(%...))または配列(keys(@...))をkeysに渡す必要があります。


参照配列のキーを取得するには、次の

keys(@{ $ref }) 

それとも単に:もちろん

0 .. $#{ $ref } 

を、対象物の内部にアクセスし、あなたの問題があります。あなたのコードは、おそらく次のようになります。

my $is_as_s = $go->get_is_as(); 
my $isaCount = @$is_as_s; 

for my $is_as (@$is_as_s) { 
    ok($is_as); 
} 
関連する問題