campbell has asked for the wisdom of the Perl Monks concerning the following question:
How do I add an extra key/value pair to an existing hash?
For example, if I have a hash like this:
%hash=(a=>1, b=>2, c=>3)
how do I add on the scalar values d and 4 to get
%hash=(a=>1, b=>2, c=>3, d=>4)?
Can I use push, as for an array?
This is probably a really basic question, but I can't find an answer to it anywhere. The Camel book only seems to give the 'push' commands for arrays, not hashes, and there is nothing listed under 'hash processing' for adding elements. Do I have to turn my hash into an array, push my values, and then turn the array back into a hash again?
Kind regards,
Campbell
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: adding key/value pairs to a hash.
by cbro (Pilgrim) on Jun 20, 2003 at 13:58 UTC | |
|
Re: adding key/value pairs to a hash.
by bobn (Chaplain) on Jun 20, 2003 at 13:59 UTC | |
|
Re: adding key/value pairs to a hash.
by nite_man (Deacon) on Jun 20, 2003 at 13:59 UTC | |
|
Re: adding key/value pairs to a hash.
by flounder99 (Friar) on Jun 20, 2003 at 16:58 UTC | |
|
Re: adding key/value pairs to a hash.
by perlguy (Deacon) on Jun 20, 2003 at 19:59 UTC | |
|
Re: adding key/value pairs to a hash.
by campbell (Beadle) on Jun 20, 2003 at 14:00 UTC |