On Mar 12, 2009, at 12:52 AM, Chas. Owens wrote:

On Thu, Mar 12, 2009 at 01:27, Chap Harrison <c...@pobox.com> wrote:

It's still not intuitive to me why we FIRST "convert" the hash to an array, and THEN ask for keys - keys being hash-ish, rather than array-ish sorts of things. (I've said that badly.) What exactly are the elements of the array
@{$hash{adams...@keys} ?
snip

It isn't really becoming an array.  A better way to think of it is
that $ means we expect one value back from the data structure:

Let me break this expression down according to my current understanding.

@{$hash{adams...@keys} = @values;

parses as follows:

adams  : short for 'adams', a string literal, being used as a hash key
$hash{adams} : the value in the hash associated with 'adams', a scalar (always), and a ref to a hash in this case {$hash{adams}} : extra braces, used to force correct "binding" (?) with surrounding context, I expect. {$hash{adams...@keys} : the hashref is dereferenced, and a set of keys (provided by an array) is looked up in the hash, resulting in a set of values; or, more precisely, *aliases* of values. @{$hash{adams...@keys} : an array of aliases of the hash values associated with the keys supplied in @keys.
@{$hash{adams...@keys} = @values : behaves much like...

( $hash{adams}{a}, $hash{adams}{ar}, $hash{adams}{af}, $hash{adams} {aw} ) = ( 1, 19, 13, 11 )


So that's my own badly-described understanding of how that expression does what it does. I'd greatly appreciate any corrections.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to