in reply to chained hash slices?

@h{@a} returns a list, so adding curly braces for slicing doesn't make sense at all:
use strict; use warnings; use Data::Dumper; my %h = ( a => {b => 1}, c => {d => 2}, ); my @a = qw(a c); print Dumper @h{@a}; __END__ $VAR1 = { 'b' => 1 }; $VAR2 = { 'd' => 2 };

If you want to slice that list, slice the indexing array instead:

my %h = ( a => {b => 1}, c => {d => 2}, ); my @a = qw(a b c); print Dumper @h{@a[0, 2]};

Replies are listed 'Best First'.
Re^2: chained hash slices?
by ikegami (Patriarch) on Jun 03, 2008 at 06:40 UTC
    None of the following exist, so the result should be a list with 6 undef.
    • $h{a}{0}
    • $h{a}{2}
    • $h{b}{0}
    • $h{b}{2}
    • $h{c}{0}
    • $h{c}{2}
      So it seems the OP wants chained slice-dereferencing braces to calculate a cross product. That would be very unlike anything perl does at the moment.

      I don't see how @hash{@list}{@list} could work without being horribly magical, inconsistent and counter-intuitive. @hash{@list} returns a list of hash references, not a hash.

      If you want to change that, you'd have to invent a syntax like %hash{@list}, which merges all the hash refs into a single hash, which can be sliced in turn.

      And then you'd have to find a good way to deal with duplicates in the new hash.