Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Can I create hash dynamically by looping through an array? The hash name should be the array element

by choroba (Chancellor)
on Jan 25, 2013 at 12:51 UTC ( #1015340=note: print w/replies, xml ) Need Help??


in reply to Can I create hash dynamically by looping through an array? The hash name should be the array element

Yes, you can - if you are not using strict refs:
for my $element (qw/var1 var2 var3/) { %$element = ( a => 'b'); } print $var1{a};
The common practice, though, is to use one hash instead, making the elements of the list the keys. You can then shorten the creation to
my @array = qw(var1 var2 var3); my %hash; undef @hash{@array};
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
  • Comment on Re: Can I create hash dynamically by looping through an array? The hash name should be the array element
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1015340]
help
Chatterbox?
[choroba]: Your votes in your profile?
[ambrus]: pryrt: yes, there is. link "Your votes" from your profile page.
[ambrus]: (That link work two ways: from your own profile page, it lists all your votes; from anyone else's profile page, it lists your votes on that user's nodes only.)
[choroba]: Wow, and I can create an interesting statistics from it
[LanX]: I've also added a link "my votes" to the personal nodelet
[pryrt]: Thanks, that was what I was looking for

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (13)
As of 2017-03-29 13:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (351 votes). Check out past polls.