Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Don't ask to ask, just ask
 
PerlMonks  

Re: How do I dynamically create a hash table?

by Anonymous Monk
on Oct 19, 2004 at 14:42 UTC ( [id://400626]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to How do I dynamically create a hash table?

In only 1 line!
%new_hash = (split(/;/,$variable_with_keys_and_values));
For example:
%new_hash = (split(/;/,'apple;good;banana;good;citrus;good;no doughnut +;bad cop')); print $new_hash{'no doughnut'};
Outputs the value associated with the key 'no doughnut'

Replies are listed 'Best First'.
Re: Answer: How do I dynamically create a hash table? (A straightforward Q, I know!)
by TedPride (Priest) on Oct 19, 2004 at 19:35 UTC
    This would probably be more clear if you said print $new_hash{'doughnut'}; instead of print $new_hash{'no doughnut'}; There is no item with key 'no doughnut'.
      Thanks; Anonymous Monk had originally had everything say "doughnut". one of the QandAEditors changed it to "no doughnut" and apparently flubbed it. Now fixed.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://400626]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.