![]() |
|
Perl-Sensitive Sunglasses | |
PerlMonks |
hash deref confusion: Intermediate Perlby live4tech (Sexton) |
on Jul 30, 2012 at 06:24 UTC ( #984356=perlquestion: print w/replies, xml ) | Need Help?? |
live4tech has asked for the wisdom of the Perl Monks concerning the following question: Almost through the Intermediate Perl book and came across code I do not understand and that was not explained clearly (seems to happen to me frequently in this book!). Here is the code:
As background: $self is a blessed hash reference. The method 'name' returns a scalar string. %STANDINGS is a hash that is associated with a DBM file. My question: I do not understand the line @$self{qw(wins places shows losses)} = @standings;
I see that @standings becomes a list of 4 numbers as a result from splitting on spaces. But, in the next line, "@$self" is syntax for dereferencing an array reference, not a hash reference! Further, the use of the "{" after this indicates a hash, but I have never seen a hash defined in this way. Are they actually saying that you can have a list of keys ("qw(wins places shows losses)") and set the values by setting this to the list "@standings"?? Really? PERL always seems to confound me with syntax! And when I cannot find the answer in perldocs etc. I just thorw up my hands and post it here! THANK YOU for being there monks!
Back to
Seekers of Perl Wisdom
|
|