Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Answer: How do I dynamically create a hash table?

by tedv (Pilgrim)
on Oct 27, 2000 at 20:54 UTC ( #38849=categorized answer: print w/replies, xml ) Need Help??

Q&A > hashes > How do I dynamically create a hash table? - Answer contributed by tedv

use strict; my %hash = (); foreach $value (@some_list) { my $key = make_some_key($value); $hash{$key} = $value; }

In other words, just assign a new key/value pair using $hash{$key} = $value. It's the logical compliment of how you'd access a hash value: $value = $hash{$key}

-Ted

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2018-05-21 17:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?