Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
There's more than one way to do things

Comment on

A bit debugging like so
sub STORE { warn "STORE: ".join(', ',map{"'$_'"} @_)."\n"; ...


STORE: 'FlatHash=ARRAY(0x820fd58)', 'Monkey', 'HASH(0x820fd88)'

at the first store attempt - your $_[2] isn't what you expect. What is happening here?

Storing the value "Eating", a FETCH is done first, which you don't see, because Tie::Hash does this for you. Since FETCH doesn't return anything, an anonymous hash is autovivified and passed into STORE as the value. This value is stored under the (lowercased) key 'monkey'. Done with the tied hash. The autovivified anonymous hash is not tied. This hash is thereafter populated with the key/value pair (habits,Eating).

At the second assignment, the value stored under the key 'monkey' is retrieved - the anonymous hash, which is not tied, and then a normal store operation is done: the value 'Eating' in that anonymous hash is overwritten with 'Scratching'. The tied hash is involved only at FETCH.

Did you read notice the 'FETCH' sub in Re: How to tie multilevel (multidimensional) hash?? It takes care that the value retrieved is of the right type (a tied hash), so that autovivification does not happen.

Ultimately I'd like the final datastructure to be something like:
$VAR1 = { 'monkey' => { 'habits' => ['Eating', 'Scratching'] } };

This is not what you said at the beginning:

I'm ultimately trying to concatenate keys of the subhashes together where the top-level key matches ignoring case.

That would be

$VAR1 = { 'monkeyhabits' => 'Scratching' }

What are you really trying to do? And why?


                              /\_¯/(q    /

In reply to Re: Tied multidimensional hashes by shmem
in thread Tied multidimensional hashes by davis

and:  <code> code here </code>

  • Please read these before you post! —
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (6)
    As of 2014-03-13 21:13 GMT
    Find Nodes?
      Voting Booth?

      Have you used a cryptocurrency?

      Results (290 votes), past polls