bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
I thought this would be covered in the Q&A, but either it was overlooked or simply impossible or unnecessary. Never-the-less, it's bugging me.
Is it possible to add the key and value to a hash at the same time? I know the accepted way is:
my %info = ( address => '123 Main', city => 'Anytown' ); $info{name} = "Bill";
And even though the following won't work, it illustrates what I would like to do:
%info .= ( name => 'Bill' ); OR push ( %info, 'name' => 'Bill' );
Why? Clarity and perceived ease of populating a hash. Thanks for your comments.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Adding to a hash?
by davido (Cardinal) on May 19, 2005 at 00:38 UTC | |
by bradcathey (Prior) on May 19, 2005 at 00:43 UTC | |
|
Re: Adding to a hash?
by Zaxo (Archbishop) on May 19, 2005 at 00:37 UTC | |
|
Re: Adding to a hash?
by Fletch (Bishop) on May 19, 2005 at 00:36 UTC | |
by bradcathey (Prior) on May 19, 2005 at 00:40 UTC |