Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
A bit debugging like so
sub STORE { warn "STORE: ".join(', ',map{"'$_'"} @_)."\n"; ...

reveals

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?

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (9)
    As of 2014-09-19 08:15 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (133 votes), past polls