[Israel.pm] Importing values from a 2D hash into another 2D hash

Meir Guttman meir at guttman.co.il
Tue Oct 30 07:47:12 PDT 2012

Thank you Sawyer and Ran. Intriguing… 

But I was thinking about something akin to how one combines two simple
hashes as:

%combined_hash = (%combined_hash, %added_hash);

(This of course overwrites same-key records, but in my application this is a
“feature” and a bonus... J)

My problem was that I was lost and couldn’t figure out how to deal with all
these references to anonymous inner hashes. L




From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf
Of sawyer x
Sent: יום ב 29 אוקטובר 2012 21:07
To: Perl in Israel
Subject: Re: [Israel.pm] Importing values from a 2D hash into another 2D



On Mon, Oct 29, 2012 at 9:04 PM, Ran Eilam <ran.eilam at gmail.com> wrote:

Returning a new value instead of mutating the sub arguments:

sub combine_values {
  my $old = shift;
  my $new  = shift;
  return map {$_ => {
      %{ $old->{$_} },
      %{ $new->{$_} || {} }
  }} keys %$old;


Perl mailing list
Perl at perl.org.il


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.perl.org.il/pipermail/perl/attachments/20121030/3dac44ae/attachment.htm 

More information about the Perl mailing list