SPUG: deferencing a hash in an array of hashes
Colin Meyer
cmeyer at helvella.org
Tue Nov 7 15:11:43 CST 2000
On Mon, Nov 06, 2000 at 05:54:45PM -0800, Todd Wells wrote:
> Yes, as I've discovered thanks to several kind SPUGgers, the debugger output
> is what had me fooled -- in reality I did it exactly right the first time.
> My eyes told me I was looking at a flat list rather than key-value pairs.
The debugger output wasn't fooling you - you were looking at a
flat list:
-----------------------
%hash = ( 1 => 'a', 2 => 'b', 3 => 'c');
print "$_ => $hash{$_}\n" for sort keys %hash;
@a = %hash;
print "\n at a\n";
@a = reverse @a;
print "\n at a\n";
%hash = @a;
print "$_ => $hash{$_}\n" for sort keys %hash;
-----------------------
Passing a hash to the debugger's 'x' function (or any other perl sub)
evaluates the hash in list context, which turns out to be a list of
name => value pairs.
-C.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
mailing list