We now have key-value slices.
$ perl -e'%h=(a=>6,b=>7,c=>8); CORE::say for %h{qw( a b )};'
a
6
b
7
So we can easily retrieve a list of key-value pairs. Adding key-value pairs
to a hash, on the other hand, isn't as nice. Do so requires
my %kvpairs = @kvpairs;
@h{ keys(%kvpairs) } = values(%kvpairs);
or
use List::Util qw( pairkeys pairvalues );
@h{ pairkeys(@kvpairs) } = pairvalues(@kvpairs);
or
%h = ( %h, @kvpairs );
None of those are great. Would there be any problems with supporting
push %hash, @kvpairs;
and of course
push $hash->%*, @kvpairs;
These are currently compilation errors. These do not have the same problem
as `push REF, LIST` had (which was that certain references can be
considered both a hash and an array).
- Eric "ikegami" Brine
$ perl -e'%h=(a=>6,b=>7,c=>8); CORE::say for %h{qw( a b )};'
a
6
b
7
So we can easily retrieve a list of key-value pairs. Adding key-value pairs
to a hash, on the other hand, isn't as nice. Do so requires
my %kvpairs = @kvpairs;
@h{ keys(%kvpairs) } = values(%kvpairs);
or
use List::Util qw( pairkeys pairvalues );
@h{ pairkeys(@kvpairs) } = pairvalues(@kvpairs);
or
%h = ( %h, @kvpairs );
None of those are great. Would there be any problems with supporting
push %hash, @kvpairs;
and of course
push $hash->%*, @kvpairs;
These are currently compilation errors. These do not have the same problem
as `push REF, LIST` had (which was that certain references can be
considered both a hash and an array).
- Eric "ikegami" Brine