> If I understand your question correctly, then yes.

I'm afraid you don't.

The old approach is fine as long as you only read from the data structure without changing it...

(The fact that the output of Data::Dump is confusing you doesn't mean it doesn't "work".)

DB<82> $hash{$_} = $value for @keys; DB<83> x \%hash 0 HASH(0x3598330) 'Prefix1=A:b:1' => HASH(0x35a48e8) 'a' => 1 'b' => 2 'Prefix1=A:b:2' => HASH(0x35a48e8) -> REUSED_ADDRESS 'Prefix1=A:c:1' => HASH(0x35a48e8) -> REUSED_ADDRESS 'Prefix1=A:c:2' => HASH(0x35a48e8) -> REUSED_ADDRESS DB<84> p $hash{'Prefix1=A:b:1'}{a} 1 DB<85> p $hash{'Prefix1=A:b:1'}{b} 2 DB<86> p $hash{'Prefix1=A:c:2'}{b} # reading works! 2 DB<87>

but once you try to add more data it'll be mirrored, because all values of the outer hash point to the same inner hash.

(Like a symlinked directory if this helps)

DB<87> p $hash{'Prefix1=A:c:2'}{X}=42 # new entry 42 DB<88> x \%hash 0 HASH(0x3598330) 'Prefix1=A:b:1' => HASH(0x35a48e8) # appears everywhere 'X' => 42 'a' => 1 'b' => 2 'Prefix1=A:b:2' => HASH(0x35a48e8) -> REUSED_ADDRESS 'Prefix1=A:c:1' => HASH(0x35a48e8) -> REUSED_ADDRESS 'Prefix1=A:c:2' => HASH(0x35a48e8) -> REUSED_ADDRESS DB<89>

So in case you want to store more data inside the inner hashes, which are supposed to be different, you have to clone the hashes.

> what would be wrong with this kind of strategy:

Sorry, I don't have even time to discuss all the traps here.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice


In reply to Re^9: Combinations of lists, etc by LanX
in thread Combinations of lists to a hash by tel2

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.