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

Micha mickey75 at gmail.com
Tue Oct 30 09:22:12 PDT 2012


maybe:
use Hash::Merge qw(merge);
%combined_hash = %{ merge( \%combined_hash, \%added_hash ) };

Cheers,
Micha

On Tue, Oct 30, 2012 at 3:47 PM, Meir Guttman <meir at guttman.co.il> wrote:

> 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****
>
> Meir****
>
> ** **
>
> ** **
>
> *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 hash****
>
> ** **
>
> Booya!****
>
> 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;
> }
>
> Ran****
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://mail.perl.org.il/mailman/listinfo/perl****
>
> ** **
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://mail.perl.org.il/mailman/listinfo/perl
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.perl.org.il/pipermail/perl/attachments/20121030/cee071de/attachment.htm 


More information about the Perl mailing list