hi, i have following code:
my @a; for (my $i=0;$i<10;$i++) { my $filenum_str = sprintf "%03d", $i; my $filename = "/var/tmp/${filenum_str}"; my %b; create_hash_for_filename($filename,\%b); push @a, {%b}; } for my $key (keys %{$a[0]}) { for my $j (1..$#a) { if (exists $a[$j]{$key}) { #adding column 1 and 2 in 1st hash if found in other hashe +s and deleting from them $a[0]{$key}[0] +=$a[$j]{$key}[0]; $a[0]{$key}[1] +=$a[$j]{$key}[1]; # delete 1st and 2 nd column from other hashes delete $a[$j]{$key}; } } } print "now printing merged firat hash: for my $key (keys %{$a[0]}) { print "$key : $a[0]{$key}[0]: $a[0]{$key}[0] \n"; } sub create_hash_for_filename { my ($file , $hash) = @_; open (FILE, "< $file") or do { return(1,"$file couldnt be opened"); }; while(<FILE>) { my @match = split (' ', $_); $hash->{$match[0]} = [$match[1], $match[2]]; } close(FILE); }
I am tryngi to create an array of 10 hashes and then trying to merge all 9 hashes in 1st hash. But second for loop doing it does not produce any output. Can somebody tell me what is wrong in the way I am access these hashes from the array. Jimmy update-> Now printed and added code for the subroutine for creating hash

In reply to array of hashes question by jimmy78

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.