Thanks for fixing the formatting; however, instead of creating a new post you can just edit the original (see "How do I change/delete my post?"). Don't worry about the original (Re^2: Multidimensional hash help!): I've requested that it be reaped.

When you post, please be specific about what you're doing. In this case, I've guessed $symb refers to the Symbol column. $UniID and $TaX are unclear (there's two columns with ID and two with Taxon): UniID and TaX may be standard abbreviations where you work (or generally in your industry) but I don't work in your industry nor do most of the people here who could help you.

The number of levels of the hash shouldn't be an issue: I'm guessing another nested for loop would've accessed all the data. In the script below, I've added another level (to what I had in my previous script) and shown how to print the fields. [For future reference, you'll find logically indenting your code makes it a lot easier to read and maintain (compare your code with mine).]

Data::Dump (which I used in my previous script) is a CPAN module which you may need to install. Data::Dumper is a built-in module. I've shown usage examples of both for comparison — you'll need click on "Reveal this spoiler" to see the output.

#!/usr/bin/env perl use strict; use warnings; use autodie; use constant { ID => 0, SYMBOL => 1, TAXON_NAME => 3, GO_ID => 5, GO_NAME => 6, }; my $file = './pm_1076856.tsv'; my %go_hash; open my $fh, '<', $file; while (<$fh>) { next if $. == 1; my @cols = split /\t/; $go_hash{$cols[SYMBOL]}{$cols[ID]}{$cols[TAXON_NAME]}{$cols[GO_ID] +} = $cols[GO_NAME]; } close $fh; for my $symbol (sort keys %go_hash) { for my $id (sort keys %{$go_hash{$symbol}}) { for my $taxon_name (sort keys %{$go_hash{$symbol}{$id}}) { for my $go_id (sort keys %{$go_hash{$symbol}{$id}{$taxon_n +ame}}) { print join("\t" => $symbol, $id, $taxon_name, $go_id, $go_hash{$symbol}{$id}{$taxon_name +}{$go_id} ), "\n"; } } } } { print "\nData::Dumper Output:\n"; use Data::Dumper; local $Data::Dumper::Indent = 1; print Dumper \%go_hash; } print "\nData::Dump Output:\n"; use Data::Dump; dd \%go_hash;

Output:

Symbol1 H1SXX9 Homo Sapiens GO:0015031 protein transport Symbol2 H1SXZ5 Homo Sapiens GO:0003824 catalytic activity Symbol2 H1SXZ5 Homo Sapiens GO:0008152 metabolic process Symbol2 H1SXZ5 Homo Sapiens GO:0008728 GTP diphosphokinase + activity Symbol2 H1SXZ5 Homo Sapiens GO:0015969 guanosine tetraphos +phate metabolic process Symbol2 H1SXZ5 Homo Sapiens GO:0016301 kinase activity Symbol2 H1SXZ5 Homo Sapiens GO:0016310 phosphorylation Symbol2 H1SXZ5 Homo Sapiens GO:0016597 amino acid binding Symbol2 H1SXZ5 Homo Sapiens GO:0016740 transferase activit +y Symbol3 H1SXZ8 Homo Sapiens GO:0006812 cation transport Symbol3 H1SXZ8 Homo Sapiens GO:0008324 cation transmembran +e transporter activity Symbol3 H1SXZ8 Homo Sapiens GO:0030001 metal ion transport Symbol3 H1SXZ8 Homo Sapiens GO:0046872 metal ion binding Symbol3 H1SXZ8 Homo Sapiens GO:0055085 transmembrane trans +port Symbol4 H1SY02 Homo Sapiens GO:0006810 transport Symbol4 H1SY02 Homo Sapiens GO:0008565 protein transporter + activity Symbol4 H1SY02 Homo Sapiens GO:0015031 protein transport Symbol5 H1SY06 Homo Sapiens GO:0004129 cytochrome-c oxidas +e activity Symbol5 H1SY06 Homo Sapiens GO:0005506 iron ion binding

-- Ken


In reply to Re^3: Multidimensional hash help! by kcott
in thread 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.