SPUG: deferencing a hash in an array of hashes
Alex.Leites at esca.com
Mon Nov 6 19:43:09 CST 2000
> I have a subroutine which builds up an array of hashes
> in @attributes, and then I want to use one of those
> hashes as it's returned value.
> return $attributes; # returns the hash reference in the array.
... just as expected, since the array of hashes is,
strictly speaking, the array of hash references.
> Alas! This doesn't do what I want, now:
> DB<6> x %hash
> 0 'ishidden'
> 1 'false'
> 2 'isreadable'
> Can someone please show me the error of my ways?
There is no error, this does do what you want.
You did not explain why you think this is wrong ...
Is that because you expected %hash to be printed as before,
with key => value format? Well, perl debugger won't do that
for "simple" hashes ("simple" meaning that there are
no references among the values) -- the other format is
reserved for more complicated data structures.
Try 'x \%hash' if you want to cheat. Or use Data::Dumper.
The only other potential source of confusion, as I see it,
is that any hash can (and evaluated in list context, will)
be regarded as an array with an even number of elements --
-- but this has already been addressed in other replies.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
More information about the spug-list