in reply to Will Perl 6 abbreviate this indirection for me?

The syntax you require is already available, albeit a little obscure.

my $href; @{ $href }{ 'a' .. 'z' } = 1 .. 26; my @required_fields = qw[ a c e g i k m o q s u w y ]; for my $k ( \( @h{ @required_fields } ) ){ print $$k; } 1 3 5 7 9 11 13 15 17 19 21 23 25

Note however, that once you make $k an alias to the value, you no longer have access to the related key, so you cannot use it in your error message. This would also be the case with your 'used_as' syntax.

In order to have both the key and an alias to the value available, you would need to use syntax like

while( my( $kref, $vref ) = \( each %{ $href } ) ) { print $$kref, ' => ', $$vref; }

Which achieves this, but the problem is now that you have lost the ability to constrain the keys over which you iterate. About the best you might do in this case is to add a next if .... clause in the loop, but comparing each keys against every entry in your @required_fields array is ludicrous:). So now you might create a lookup (another hash) for just the required keys and grep against that but....:)

I keep thinging about P6s Pair and Binding operators ==> and <==, and trying to work out in my minds eye how these might be combined with a hash slice to achieve your goal, but whilst I can follow and relish TheDamians exogesies, remembering enough of the syntax and semantics to start trying to put together my own snippets is well beyond me at this stage. Maybe he'll happen by and put us out of our misery!


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.