|Syntactic Confectionery Delight|
Merge 2 hashes which contains duplicate Keysby slayedbylucifer (Scribe)
|on Sep 25, 2012 at 18:40 UTC||Need Help??|
slayedbylucifer has asked for the
wisdom of the Perl Monks concerning the following question:
THis question is regarding merging two hashes with duplicate keys. I found few solutions on hte internet and they all work, but I could not understand any of them . Hence working it out on my own.
Also, I tried the Hash::Merge and it works too, but I am feeling that this is not really that diffuclt and hence want to do it myself.
Lets consider below 2 hashes:
I want to merge these two hash so that the resulting hash look like below:
So when a duplicate key is found, the value of that key should get into an anonymous array
I referred http://perldoc.perl.org/perlreftut.html and wrote below code:
the output is:
So, I remove "use strict" and I get below output:
I am not able to figure out where I am going wrong. Any suggestions would be of great help.