After studying examples in "Effective Perl Programming" I devised the 
following working code snippet:

@people{@newkeys} = @$contact{sort keys %$contact};

I am trying to understand exactly how and why it works.
This appears in a subroutine that is passed a hash reference ($contact)
@newkeys is declared as a lexical in this subroutine, as is %people.

So I understand what sort keys %$contact is doing , it is simply 
dereferencing the hash reference, passing the resulting hash to the 
function keys and sorting the list returned.

I can see how something like

my ($mday,$month,$year) = (localtime)[3..5] #or whatever those indices 
should be

works. The parentheses put the return values of localtime into a list 
context which can then be indexed, correct?

Yet I'm still confused about the mechanics of how you can assign to an 
array slice of a hash. Anyone have a good explanation?

Thanks
Peter Cline
Inet Developer
New York Times Digital

Reply via email to