[Israel.pm] Importing values from a 2D hash into another 2D hash
Meir Guttman
meir at guttman.co.il
Thu Nov 1 07:21:50 PDT 2012
Thanks Micha!
Once again, CPAN to the rescue. But how do you find the right module???
As for this Hash::Merge package, it seems a cannon, and all I needed was to kill a mosquito…
Regards to all,
Meir
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf Of Micha
Sent: יום ג 30 אוקטובר 2012 18:22
To: Perl in Israel
Subject: Re: [Israel.pm] Importing values from a 2D hash into another 2D hash
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/20121101/d4ffd283/attachment.htm
More information about the Perl
mailing list