in reply to Re: Re: A hash of an array containing hashes & arrays
in thread A hash of an array containing hashes & arrays
... prints "ARRAY". But if for some reason you're testing the stringification of an array reference (not the return value of ref), then you shouldn't use eq.perl -le '$foo{"bar"} = ["a","b"]; print ref $foo{"bar"}'
What are you expecting to see in your output? Hashes are not interpolated into strings, but arrays are, so printing "Array in Array item: @$item" should print the array elements in $item. A clearer way would be a foreach loop or map, perhaps like this:
if (ref $item eq 'ARRAY') { print "Array in Array item:\n"; foreach (@$item) { print " $_\n"; } } elsif (ref $item eq 'HASH') { print "Hash in Array item:\n"; foreach (keys %$item) { print " $_ -> $item->{$_}\n"; } } else { print "Array Item: $item\n"; }
-- Mike
--
just,my${.02}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: A hash of an array containing hashes & arrays
by ebodine (Novice) on Aug 21, 2002 at 21:35 UTC | |
by Bird (Pilgrim) on Aug 22, 2002 at 17:55 UTC | |
by ebodine (Novice) on Aug 22, 2002 at 21:52 UTC |