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

Re: key/value hash slices summary

Thread Previous | Thread Next
Salvador Fandino
July 2, 2013 08:43
Re: key/value hash slices summary
Message ID:
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;


  %h{...} = @pairs;
  %h1{...} = %h2;

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About