Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: hash deref confusion: Intermediate Perl

by AnomalousMonk (Archbishop)
on Jul 30, 2012 at 13:35 UTC ( #984448=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://984448]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2023-02-04 21:41 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (31 votes). Check out past polls.