Hello all,

I am sure you would have heard this all before but I shall say it again. I am a new user of perl and would like help defining my hash. I have an input text file containing 11 columns of information that I have initialized. A snippet of the file and my code are shown below.

File: ID Symbol Taxon Taxon Name Evidence GO ID GO Name + Aspect Reference With Source H1SXX9 Symbol1 12345 Homo Sapiens IEA GO:0015031 pro +tein transport Process GO_REF:0000002 InterPro:IPR027282 +InterPro H1SXZ5 Symbol2 12345 Homo Sapiens IEA GO:0003824 cat +alytic activity Function GO_REF:0000002 InterPro:IPR003607 + InterPro H1SXZ5 Symbol2 12345 Homo Sapiens IEA GO:0008152 met +abolic process Process GO_REF:0000002 InterPro:IPR002912 +InterPro H1SXZ5 Symbol2 12345 Homo Sapiens IEA GO:0008728 GTP + diphosphokinase activity Function GO_REF:0000003 EC:2.7.6.5 + UniProt H1SXZ5 Symbol2 12345 Homo Sapiens IEA GO:0015969 gua +nosine tetraphosphate metabolic process Process GO_REF:0000002 + InterPro:IPR004811|InterPro:IPR007685 InterPro H1SXZ5 Symbol2 12345 Homo Sapiens IEA GO:0016301 kin +ase activity Function GO_REF:0000038 UniProtKB-KW:KW-0418 + UniProt H1SXZ5 Symbol2 12345 Homo Sapiens IEA GO:0016310 pho +sphorylation Process GO_REF:0000038 UniProtKB-KW:KW-0418 +UniProt H1SXZ5 Symbol2 12345 Homo Sapiens IEA GO:0016597 ami +no acid binding Function GO_REF:0000002 InterPro:IPR002912 + InterPro H1SXZ5 Symbol2 12345 Homo Sapiens IEA GO:0016740 tra +nsferase activity Function GO_REF:0000038 UniProtKB-KW:KW-08 +08 UniProt H1SXZ8 Symbol3 12345 Homo Sapiens IEA GO:0006812 cat +ion transport Process GO_REF:0000002 InterPro:IPR002524 I +nterPro H1SXZ8 Symbol3 12345 Homo Sapiens IEA GO:0008324 cat +ion transmembrane transporter activity Function GO_REF:0000002 + InterPro:IPR002524 InterPro H1SXZ8 Symbol3 12345 Homo Sapiens IEA GO:0030001 met +al ion transport Process GO_REF:0000002 InterPro:IPR006121 + InterPro H1SXZ8 Symbol3 12345 Homo Sapiens IEA GO:0046872 met +al ion binding Function GO_REF:0000002 InterPro:IPR006121 + InterPro H1SXZ8 Symbol3 12345 Homo Sapiens IEA GO:0055085 tra +nsmembrane transport Process GO_REF:0000002 InterPro:IPR0025 +24 InterPro H1SY02 Symbol4 12345 Homo Sapiens IEA GO:0006810 tra +nsport Process GO_REF:0000002 InterPro:IPR002898 InterPro H1SY02 Symbol4 12345 Homo Sapiens IEA GO:0006810 tra +nsport Process GO_REF:0000038 UniProtKB-KW:KW-0813 UniPro +t H1SY02 Symbol4 12345 Homo Sapiens IEA GO:0008565 pro +tein transporter activity Function GO_REF:0000002 InterPro:I +PR002898 InterPro H1SY02 Symbol4 12345 Homo Sapiens IEA GO:0015031 pro +tein transport Process GO_REF:0000038 UniProtKB-KW:KW-0653 + UniProt H1SY06 Symbol5 12345 Homo Sapiens IEA GO:0004129 cyt +ochrome-c oxidase activity Function GO_REF:0000002 InterPro: +IPR000883|InterPro:IPR004677|InterPro:IPR023615|InterPro:IPR023616 + InterPro H1SY06 Symbol5 12345 Homo Sapiens IEA GO:0004129 cyt +ochrome-c oxidase activity Function GO_REF:0000003 EC:1.9.3. +1 UniProt H1SY06 Symbol5 12345 Homo Sapiens IEA GO:0005506 iro +n ion binding Function GO_REF:0000002 InterPro:IPR000883 +InterPro
Code: open(IN,$annotationfile) or die "Can't open $annotationfile\n"; while(<IN>){ chomp; @data = split(/\t/,$_); $Column1 = @data[0]; $Column2 = @data[1]; $Column3 = @data[2]; $Column4 = @data[3]; $Column5 = @data[4]; $Column6 = @data[5]; $Column7 = @data[6]; $Column8 = @data[7]; $Column9 = @data[8]; $Column10 = @data[9]; $Column11 = @data[10]; print "$Column1\t$Column2....\t$Column11\n"; foreach $_ (1..$#data){ $GOHash{"$Symbols"}{"$GO_Names"} = "$IDs"; foreach $Symbols (@data) { foreach my $name (sort {$a <=> $b} (keys %GOHash) ) { foreach my $annotation (keys %{ $GOHash{$name} }) { print "$name, $annotation: $GOHash{$name}{$annotation}\n"; close(IN); } } } } }

I know that my columns are initialized because I see the correct information when I print. I am experiencing problems creating a multidimensional hash. Sorry that the syntax is not correct, I did it for simplicities sake,however this is what I would like to hash: % hash1 = Column1 => Column 2. %hash2 = %hash1 => Column3. %hash3 = %hash2 => Column 4.

I would be thankful for any help/advice. Kind regards, Ila14 </>


In reply to Multidimensional hash help! by ila14

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.