Couple things... First, you don't want to use eq when checking the result of your ref() call, because it'll never match. The ref($item) will return a value like HASH(0x8580988), so you only want to see if it contains the string "HASH". Like so...
if (ref($item) =~ /HASH/) {}
Second, if you're trying to print out the actual values in the hash or array referenced in your top-level array, you're going to need to dereference them.
print "Array in Array: ", @{$item}, "\n"; ... print "Hash in Array: ", %{$item}, "\n";
...and so you end up with something like...
#!/usr/bin/perl -w use strict; $, = " "; my %Volume_Info = ( alpha => [ 0, 512, 1048576, 1, { one => 'first_hash' }, [ 'two', 'first_array' ], { three => 'second_hash' }, -1, 0, 0, 0, 0, 0, 'zfod', 0 ], beta => [ 1, 2, 3, { four => 'third_hash' }, 2, 1 ] ); for my $vol_key ( sort keys %Volume_Info ) { print "\nVolume: $vol_key\n"; foreach my $item ( @{ $Volume_Info{$vol_key}} ) { if (ref($item) =~ /ARRAY/) { print "Array in Array item: ", @{$item}, "\n"; } elsif (ref($item) =~ /HASH/) { print "Hash in Array: ", %{$item}, "\n"; } else { print "Array Item: $item \n"; } } }
...which produces...
Volume: alpha Array Item: 0 Array Item: 512 Array Item: 1048576 Array Item: 1 Hash in Array: one first_hash Array in Array item: two first_array Hash in Array: three second_hash Array Item: -1 Array Item: 0 Array Item: 0 Array Item: 0 Array Item: 0 Array Item: 0 Array Item: zfod Array Item: 0 Volume: beta Array Item: 1 Array Item: 2 Array Item: 3 Hash in Array: four third_hash Array Item: 2 Array Item: 1
Hope this helps.

-Bird

Update: Made my code a little more consistent across examples.

Update 2: Silly me not reading up on ref before responding. :-} See comments by thelenm and Chmrr below.


In reply to Re: A hash of an array containing hashes & arrays by Bird
in thread A hash of an array containing hashes & arrays by ebodine

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.