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 23: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.