I'm not actually joining anything; I'm using blessed-hashes-of-blessed-hashes. (I replied this privately a minute ago, but then it sparked an idea.)

But that gives me an idea, or perhaps it's what you already meant: it would be much better to use the same underlying implementation, but switch to using $; rather than a period as a separator, so that the example would be:

$cost = $h->{'Locations',$location,'Buildings',$building,'cost'};

No new syntax that way, although it does use an unfamiliar one in these post-Perl4 days. But also no smushing of keys together into one string, even if it's only temporary.

And the more I think about it, the more it looks like this is what you meant -- since my immediate reaction to typing in the example was that an interpolating qw would be really nice! But your point about it being difficult to iterate over or assign to a deeper level isn't a problem with my current implementation.

I think I'll go change my code to take an optional separator string parameter, defaulting to $;, so that you can do it either way. I'm not sure yet which I'll use; the lack of interpolation with the $; approach defeats much of the benefit.

As for Perl6 -- we could always add in more than one interpolating context. You'd still need syntax to select them, of course. How about

$code = %h{''Locations $location Buildings $building cost''};
or maybe
$code = %h{''Locations'$location'Buildings'$building'cost''};
Ironically, I think this is already possible in Parrot with multipart keys, using PIR's
$P1['Locations';$S1;'Buildings';$S2;'cost']
The current aggregates' code will pass on any leftover portions of a key to the aggregate it just retrieved.

In reply to Re^2: Dotted hash access by sfink
in thread Dotted hash access by sfink

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.