in reply to How do I populate a ML hash from an array?

Sure enough: I have values set then it tries to place the nested hash in the same level.
Here is some logs of the last set of arrays sent to the sub:
02-28-2001 15:18:46 |69 15
02-28-2001 15:18:46 |69 16
02-28-2001 15:18:46 |69 18
02-28-2001 15:18:46 |69 15 14
02-28-2001 15:18:46 |69 18 17
02-28-2001 15:18:46 |69 18 19
02-28-2001 15:18:46 |69 15 14 13
02-28-2001 15:18:46 |69 15 14 13 12
02-28-2001 15:18:46 |69 15 14 13 12 11
02-28-2001 15:18:46 |69 15 14 13 12 11 10
$hash{69}{15}
$hash{69}{18}
Are set first, so all the others are ignored. When really, the least important are the first ({69}{15} & {69}{18}) with the last in the set being critical:
$hash{69}{15}{14}{13}{12}{11}{10}
$hash{69}{18}{17}
$hash{69}{18}{19}
$hash{69}{16}
What the script is doing is going through some DB entries and trying to draw a tree from the info it finds. $hash{69}{15}{14}{13}{12}{11}{10} represents a whole leg. My ultimate goal is to draw out the pyramid. I figure that if I could load all the values into the hash, I could just do a recursive iteration of the hash to print out the tree. But since $hash{69}{15} = 1 is set first, the rest of the program errors.
  • Comment on Re: How do I populate a ML hash from an array?

Replies are listed 'Best First'.
Re (tilly) 2: How do I populate a ML hash from an array?
by tilly (Archbishop) on Mar 01, 2001 at 04:15 UTC
    Why not use an empty hash (ie {}) as your default true value? Then when $hash{69}{15} is set to {}, there is no problem setting $hash{69}{15}{14}{13} to {} after that.
      Well hot-dog!
      Thank you. I was thinking way to hard about that one for such a simple answer.
(tye)Re2: How do I populate a ML hash from an array?
by tye (Sage) on Mar 01, 2001 at 03:24 UTC

    Why don't you just use $hash{join $;, @list}= 1 instead?

            - tye (but my friends call me "Tye")
      Because that would produce:
      $hash{onetwothree} = 1
      instead of
      $hash{one}{two}{three} = 1