
chasdavies
New User
May 20, 2010, 7:34 AM
Post #1 of 2
(3759 views)
|
convert array to nested hash
|
Can't Post
|
|
I need help in determining the best method to convert an array to a nested hash. Assume I have two arrays: my @array1 = ("a", "b", "c", "d"); my @array2 = ("a", "c", "e"); What I need to do is to to merge the two arrays into a hash table where I can assign some data to the leaf node (last element) of the tree. The hass needs to look like this: my %hash = { 'a' => { 'b' => { 'c' => { d => 'some data' } }, 'c' => { 'e' => 'some other data' } } }; Any help on how to code this would be greatly appreciated.
|