Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: hash deref confusion: Intermediate Perl

by AnomalousMonk (Archbishop)
on Jul 30, 2012 at 13:35 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-19 14:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found