[Thousand-oaks-pm] Perl hash question
Aran Deltac
adeltac at valueclick.com
Fri Dec 2 10:00:32 PST 2005
Well, he wanted to preserve any existing keys in %foo, so that would be:
foreach (keys %bar) {
$foo{$_} = $bar{$_}
unless(exists $foo{$_});
};
Personally I like using map for things like this:
map { $foo{$_}=$bar{$_} unless(exists $foo{$_}) } keys(%bar);
Aran
> -----Original Message-----
> From: thousand-oaks-pm-bounces+adeltac=valueclick.com at pm.org
> [mailto:thousand-oaks-pm-bounces+adeltac=valueclick.com at pm.org] On
Behalf
> Of Jim Walker
> Sent: Friday, December 02, 2005 9:49 AM
> To: thousand-oaks-pm at mail.pm.org
> Subject: Re: [Thousand-oaks-pm] Perl hash question
>
> And, for large hashes,
>
> foreach (keys %bar) {$foo{$_} = $bar{$_}};
>
> should use less memory.
> --
> Jim
>
>
>
> Gary Ansok wrote:
>
> >Robert Hull wrote:
> >
> >
> >
> >>I'm looking for a succinct way to join two hashes. What I would
like
> is:
> >>
> >>%foo .= %bar ;
> >>
> >>Where %foo retains it values for keys undefined in %bar
> >>and
> >>%foo takes %bar values for keys defined in %bar.
> >>
> >>
> >>
> >>
> >I believe that
> >
> >%foo = (%foo, %bar);
> >
> >will do what you want.
> >
> >Gary Ansok
> >
> >_______________________________________________
> >Thousand-oaks-pm mailing list
> >Thousand-oaks-pm at pm.org
> >http://mail.pm.org/mailman/listinfo/thousand-oaks-pm
> >
> >
> >
> >
> _______________________________________________
> Thousand-oaks-pm mailing list
> Thousand-oaks-pm at pm.org
> http://mail.pm.org/mailman/listinfo/thousand-oaks-pm
More information about the Thousand-oaks-pm
mailing list