in reply to Re: Dotted hash access
in thread Dotted hash access
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
or maybe$code = %h{''Locations $location Buildings $building cost''};
Ironically, I think this is already possible in Parrot with multipart keys, using PIR's$code = %h{''Locations'$location'Buildings'$building'cost''};
The current aggregates' code will pass on any leftover portions of a key to the aggregate it just retrieved.$P1['Locations';$S1;'Buildings';$S2;'cost']
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Dotted hash access
by demerphq (Chancellor) on Dec 02, 2004 at 16:16 UTC | |
by sfink (Deacon) on Dec 03, 2004 at 04:24 UTC |