develooper Front page | perl.perl5.porters | Postings from July 2013

Re: key/value hash slices summary

Thread Previous | Thread Next
From:
Ruslan Zakirov
Date:
July 2, 2013 09:00
Subject:
Re: key/value hash slices summary
Message ID:
CAMOxC8t7aRod_Yit+1DwBsbeq-FRVGDa6x_z1b8O-yTXh-NyDw@mail.gmail.com
On Tue, Jul 2, 2013 at 12:43 PM, Salvador Fandino <sfandino@yahoo.com>wrote:

> On 07/01/2013 03:05 PM, Ruslan Zakirov wrote:
>
> >   Left value
> >     Most explicit lvalue operations on key/value hash slices throw
> errors:
> >
> >         %h{qw(a b)} = qw(A B);
> >
> >     Even:
> >
> >         %h{'a'} = 'foo';
>
> Sometimes I miss a concise way to push a list of pairs into a hash and
> also to insert the contents of some hash into another hash:
>
>   # inserting a list of pairs
>   while (@pairs) {
>     my $k = shift @pairs;
>     my $v = shift @pairs;
>     $h{$k} = $v;
>   }
>
>   # inserting another hash
>   @h1{keys %h2} = values %h2;
>
> Would it make sense to add some syntax to support that?
>
> For instance:
>
>   %h{} = @pairs;
>   %h1{} = %h2;
>
> or
>
>   %h{...} = @pairs;
>   %h1{...} = %h2;
>

It was suggested to extend push for this:

push %h, @pairs;

It was in my first summary (the one I lost to git clean). I like push idea
more than any of above, but while it's related I think that it's separate
project and I can move to it after this is complete. Somebody else can try
to implement this, shouldn't be very hard.

-- 
Best regards, Ruslan.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About