in reply to Nesting below emptiness and/or inverting a hash.

How can we invert any hash so that it is stored with its deepest keys at the top and its outer keys at the bottom of some structure?i>

I don't know about other people, butI'm having a hard time trying to visualise what you mean. Is it possible for you to 'draw a picture' or post an example? Or is it a case of needing to know the solution before you could do that?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re: Nesting below emptiness and/or inverting a hash.

Replies are listed 'Best First'.
Re^2: Nesting below emptiness and/or inverting a hash.
by Moron (Curate) on Jan 22, 2007 at 16:56 UTC
    Sure. Suppose that you can be given any hash at all, but only one slice at a time. So given the hash:
    { a => { b1=> { c11 => vc11, c12 => vc12 }, b2 => { c21 => vc21, c22 = +> vc22 } } }
    you receive it one slice at a time in reverse order but with the level at which it is stored in the hash:
    { c21 => vc21, c22 => vc22 }, level=3 { c11 => vc11, c21 => vc12 }, level=3 { b2 => ?, b1 => ? }, level=2 { a => ? }, level =1.
    You could simply test for level = 1 and then process that recursively down to level 3 (avoiding processing at level 4 being an issue). But sometimes there are reasons why you can't wait or more likely, it is just too hard or messy to stack up all the context (in my case, this is specifically the other control and literal data within the stack frame at the point the slice is first interpreted inwards) and then have to unravel it later. I might end up having to do that though anyway unless someone has a better suggestion - my initial placeholder idea (just what first popped into my head) is just too inelegant I feel.

    -M

    Free your mind