Hello, The following code successfully prints all content of a hash of arrays:
for $x ( keys %HoA ) { print "$x: "; for $i ( 0 .. $#{ $HoA{$x} } ) { print "$HoA{$x}[$i] "; } } Output looks like this: Keys: array 8001: bp ne sc ax br le no ns mn sl lt sh lw ni lu dl 5022: bp ne sc ax br le no ns mn sl lt sh lw ni lu dl 1018: bp ne br no lt lw ni l I pass the %HoA to a function and want to print all the elements of th +e %HoA—but I’m failing to do this inside the function. This is my pro +blem. (The same function that receives the HoA must also process an +array. ) some_function(\%HoA); # could be some_function(\@array) sub some_function{ $aref = shift; if (ref($aref) eq “ARRAY”){ Do something with array---I got this muchworking! } elsif (ref($aref) eq “HASH”){ #This foreach of the hash ref doesn't print anything! foreach $key ( keys %{$aref} ){ print “key: $key…..”; for ( $i = 0; $i <=100; $i++ ){ print “ $aref->{$key}[$i] “; } }
Thanks for any clues. John

In reply to accessing elements of reference to hash of arrays by johnguillory

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.