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

Re: key/value hash slices summary

Thread Previous | Thread Next
From:
Salvador Fandino
Date:
July 2, 2013 08:43
Subject:
Re: key/value hash slices summary
Message ID:
20130702084328.30031.qmail@lists-nntp.develooper.com
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;




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