Before trying to print @arr, I think you should learn how print what you call @subArr.

I changed the terminology a bit below. I called @subArr, @href_array, array of hash references.

#!/usr/bin/perl use strict; use warnings; my @href_array; #array of ref's to hash my @arr; #an array of ref's to @href_array arrays my %hash = (); my %hash2 = (); my %hash4 = (); my %hash8 = (); $hash{key} = 12; $hash{pl} = 1; $hash{lop} = 9; $hash2{key} = 88; #changed this to be different #than $hash{key} = 12 $hash4{pl} = 1; $hash8{lo} = 9; push(@href_array, \%hash); #array of ref's to hash push(@href_array, \%hash2); #array of ref's to hash push(@href_array, \%hash4); #array of ref's to hash push(@href_array, \%hash8); #array of ref's to hash dump_hashref_array (@href_array); sub dump_hashref_array # dump_hashes(\%h1,\%h2,...,\%hn) { my @hrefs = @_; my $n_table =1; foreach my $href (@hrefs) { print "dumping hash table ", $n_table++,"\n"; foreach my $key (keys %$href) { print "$key=>$href->{$key}\n"; } print "\n"; #just a spacer line between hashes } } __END__ PRINTS: dumping hash table 1 key=>12 pl=>1 lop=>9 dumping hash table 2 key=>88 dumping hash table 3 pl=>1 dumping hash table 4 lo=>9
Update: Note that push(@arr, \@href_array); would mean that @arr is an array of references to @href_array. This would add one more foreach() level to the code. I recommend study of the above before trying to add yet another level to the data structure.

A bit off topic, but I see you are flummoxed by this "1/8" sometimes result? This is kind of a weird thing, but here is how it could happen. A reference to hash could also result from different code. Anyway this is how you could get the string "1/8":

#!/usr/bin/perl use strict; use warnings; my %hash; $hash{anything} =1; my $hash_result = %hash; print "scalar value of a this hash = $hash_result\n"; __END__ PRINTS: scalar value of a this hash = 1/8 # scalar values of a hash is a string, like "1/8" # Means that 1 of 8 hash buckets is currently in use. # A Perl hash always starts with 8 hash buckets. # # Perl will double the number of hash buckets as it # sees fit. You have no control over that decision. # # Current versions of Perl have some randomization of # the keys -- a run with the exact same data may # result in a difference in # of keys used or total keys. # Of course the code above will always result in "1/8".

In reply to Re: Get hash values in multidimensional array by Marshall
in thread Get hash values in multidimensional array to populate Term document matrix by lobs

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.