http://qs321.pair.com?node_id=984448


in reply to hash deref confusion: Intermediate Perl

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?

Why not just try it and see?? A toy experimental program takes less than a minute to create and run. Really!

>perl -wMstrict -le "use Data::Dump; ;; my $self = { foo => 'bar' }; my @standings = qw(1 2 3 4); ;; @$self{ qw(wins places shows losses) } = @standings; ;; dd $self; " { foo => "bar", losses => 4, places => 2, shows => 3, wins => 1 }

Replies are listed 'Best First'.
Re^2: hash deref confusion: Intermediate Perl
by live4tech (Sexton) on Jul 30, 2012 at 14:03 UTC
    Of course, but you are taking this out of context. I would have had to know @$self{ qw... was a hash slice which was my real problem. I assumed the line worked, I did not understand the syntax.