Dear Monks,

Please look at the following code

use strict; use warnings; use Data::Dumper; open (S,"<","sample.data") or die $!; my @file=<S>; my %samplehash; my @fields; my ($key,$subkey); for ( my $i=0;$i<=$#file;$i++) { chomp $file[$i]; @fields=split /\s+/,$file[$i]; $samplehash{$fields[1]}{$fields[2]}=$fields[0]; } foreach $key (keys %samplehash) { print "\n $key = ". $samplehash{$key}; foreach $subkey (keys %{$samplehash{$key}}) { print "\t$subkey = $samplehash{$key}{$subkey} "; } } close S;

This is the input file

cow NM_178575.2 0 cow NM_181451.1 1 cow NM_001038581.1 2 cow NM_001037618.1 3 cow NM_001034757.1 4 cow NM_001076304.1 5 cow NM_001076305.1 6 cow NM_001076273.1 7 cow NM_001076486.1 8 cow NM_001076951.1 9 cow NM_001077070.1 10 cow NM_001077006.1 11 cow NM_001078104.1 12 cow NM_001078077.1 13 cow NM_001077830.1 14 cow NM_001079784.1 15 cow NM_001078135.1 16 cow NM_001080323.1 17 cow NM_001080346.1 18 cow NM_001080347.1 19 cow NM_174222.2 20 cow NM_001080364.1 21

When i try to print the key of the first hash table, using print "\n $key = ". $samplehash{$key};, i see the output something very weird as follows :

NM_001077006.1 = HASH(0x224be2c) 11 = cow

Can someone tell me the problem with my print statement, please. I didn't understand what is the HASH(0x224be2c) ,when i am expecting it to print 11


In reply to Print the key of the first hash table in hash of hashes by sundeep

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.