I'm trying to use the array slice mechanism. This code
my %a=('a',1,'b',2,'c',3);
print for @a{'a','b'};
work fine. However
my $a={'a',1,'b',2,'c',3};
print for @a->{'a','b'};
spits out the error message
Can't coerce array into hash
The quick solution is, of course, to dereference the
hash ref into a temporary variable before slicing:
my $a={'a',1,'b',2,'c',3};
my %a=%$a;
print for @a{'a','b'};
Somehow this seems ugly. So does anyone know how I can use
the arrow operator to get a hash slice directly from the
reference without the need for a temporary.