From rhull2k at earthlink.net Thu Dec 1 21:41:51 2005 From: rhull2k at earthlink.net (Robert Hull) Date: Thu, 1 Dec 2005 21:41:51 -0800 Subject: [Thousand-oaks-pm] Perl hash question References: Message-ID: <000801c5f703$1cc1e980$6400a8c0@perlguy> 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. Maybe I do not know an obvious way of doing this. The best I found is: my @temp = %foo ; push @temp,%bar ; %foo = @temp; Just wondering if a better way exists? Does my solution have unexpected side effects? Robert From ansok at alumni.caltech.edu Thu Dec 1 22:54:50 2005 From: ansok at alumni.caltech.edu (Gary Ansok) Date: Thu, 01 Dec 2005 22:54:50 -0800 Subject: [Thousand-oaks-pm] Perl hash question In-Reply-To: <000801c5f703$1cc1e980$6400a8c0@perlguy> References: <000801c5f703$1cc1e980$6400a8c0@perlguy> Message-ID: <438FEFBA.3060704@alumni.caltech.edu> 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 From jim at reclaw.com Fri Dec 2 09:49:25 2005 From: jim at reclaw.com (Jim Walker) Date: Fri, 02 Dec 2005 09:49:25 -0800 Subject: [Thousand-oaks-pm] Perl hash question In-Reply-To: <438FEFBA.3060704@alumni.caltech.edu> References: <000801c5f703$1cc1e980$6400a8c0@perlguy> <438FEFBA.3060704@alumni.caltech.edu> Message-ID: <43908925.9050702@reclaw.com> 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 > > > > From adeltac at valueclick.com Fri Dec 2 10:00:32 2005 From: adeltac at valueclick.com (Aran Deltac) Date: Fri, 2 Dec 2005 10:00:32 -0800 Subject: [Thousand-oaks-pm] Perl hash question Message-ID: <9906CF1545A50A489C7E0A734E43AE980425953F@vchqex01.wl.corp.valueclick.com> 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 From ansok at alumni.caltech.edu Fri Dec 2 10:48:19 2005 From: ansok at alumni.caltech.edu (ansok@alumni.caltech.edu) Date: Fri, 2 Dec 2005 10:48:19 -0800 (PST) Subject: [Thousand-oaks-pm] Perl hash question In-Reply-To: <9906CF1545A50A489C7E0A734E43AE980425953F@vchqex01.wl.corp.valueclick.com> References: <9906CF1545A50A489C7E0A734E43AE980425953F@vchqex01.wl.corp.valueclick.com> Message-ID: <41831.64.14.1.106.1133549299.squirrel@mail.alumni.caltech.edu> No, I don't think he wanted to preserve existing keys in %foo -- he said "%foo takes %bar values for keys defined in %bar". If he did, though, the simple way (perhaps not the best for very large hashes) would be: %foo = (%bar, %foo); Instead of your map statement, I might write it as $foo{$_} = $bar{$_} foreach grep !exists $foo{$_}, keys %bar; I don't think there's going to be a significant performance difference between the two, though. Gary Ansok Aram Deltac wrote: > 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 > > _______________________________________________ > Thousand-oaks-pm mailing list > Thousand-oaks-pm at pm.org > http://mail.pm.org/mailman/listinfo/thousand-oaks-pm > From adeltac at valueclick.com Fri Dec 2 11:02:06 2005 From: adeltac at valueclick.com (Aran Deltac) Date: Fri, 2 Dec 2005 11:02:06 -0800 Subject: [Thousand-oaks-pm] Perl hash question Message-ID: <9906CF1545A50A489C7E0A734E43AE980425967F@vchqex01.wl.corp.valueclick.com> > -----Original Message----- > From: ansok at alumni.caltech.edu [mailto:ansok at alumni.caltech.edu] > Sent: Friday, December 02, 2005 10:48 AM > To: Aran Deltac > Cc: Jim Walker; thousand-oaks-pm at mail.pm.org > Subject: Re: [Thousand-oaks-pm] Perl hash question > > No, I don't think he wanted to preserve existing keys in %foo > -- he said "%foo takes %bar values for keys defined in %bar". The full quote is "Where %foo retains it values for keys undefined in %bar and %foo takes %bar values for keys defined in %bar". The key part being "Where %foo retains it values". > If he did, though, the simple way (perhaps not the best for > very large hashes) would be: > > %foo = (%bar, %foo); > > Instead of your map statement, I might write it as > > $foo{$_} = $bar{$_} foreach grep !exists $foo{$_}, keys %bar; Oddly, you grep example and my map one are the exact same number of characters. :) I did a benchmark and it looks like your method with grep is slightly faster. I was only able to see a speed increase after running each method 10,000 times, so it's a minimal speed difference. Aran > I don't think there's going to be a significant performance > difference between the two, though. > > Gary Ansok > > Aram Deltac wrote: > > 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 > > > > _______________________________________________ > > Thousand-oaks-pm mailing list > > Thousand-oaks-pm at pm.org > > http://mail.pm.org/mailman/listinfo/thousand-oaks-pm > > From Daniel.Sherer at healthnet.com Fri Dec 9 14:57:17 2005 From: Daniel.Sherer at healthnet.com (Daniel.Sherer@healthnet.com) Date: Fri, 9 Dec 2005 14:57:17 -0800 Subject: [Thousand-oaks-pm] December PM meeting next Wednesday! Message-ID: Hey Guys, Just a reminder that our final Perl Mongers meeting of 2005 will be next Wednesday, 12/14, (normal location and time). Daniel Sherer Manager, ITG Data Warehouse Health Net (818) 676-7592 This message,together with any attachments, is intended only for the use of the individual or entity to which it is addressed. It may contain information that is confidential and prohibited from disclosure. If you are not the intended recipient, you are hereby notified that any dissemination or copying of this message or any attachment is strictly prohibited. If you have received this message in error, please notify the original sender immediately by telephone or by return e-mail and delete this message, along with any attachments, from your computer. Thank you. From Daniel at Sherer.org Tue Dec 13 13:52:44 2005 From: Daniel at Sherer.org (Daniel Sherer) Date: Tue, 13 Dec 2005 13:52:44 -0800 Subject: [Thousand-oaks-pm] Perl Monger's meeting Tomorrow (Wed) Can someone take notes? Message-ID: <2817a58f0512131352h64b2e672m8f813daf33b4e5d6@mail.gmail.com> Hey Perl Mongers! Last regular meeting of 2005 will be tomorrow. Unfortunately, I have a company function (party!) and won't be able to attend the perl meeting. Can someone pass around a sign-in sheet and maybe make some notes on the general topics discussed? Thanks! Daniel From adeltac at valueclick.com Tue Dec 13 14:43:41 2005 From: adeltac at valueclick.com (Aran Deltac) Date: Tue, 13 Dec 2005 14:43:41 -0800 Subject: [Thousand-oaks-pm] Perl Monger's meeting Tomorrow (Wed) Can someonetake notes? Message-ID: <9906CF1545A50A489C7E0A734E43AE980462400C@vchqex01.wl.corp.valueclick.com> Will do. Aran > -----Original Message----- > From: thousand-oaks-pm-bounces at pm.org [mailto:thousand-oaks-pm- > bounces at pm.org] On Behalf Of Daniel Sherer > Sent: Tuesday, December 13, 2005 1:53 PM > To: thousand-oaks-pm at mail.pm.org > Subject: [Thousand-oaks-pm] Perl Monger's meeting Tomorrow (Wed) Can > someonetake notes? > > Hey Perl Mongers! > > Last regular meeting of 2005 will be tomorrow. > > Unfortunately, I have a company function (party!) and won't be able to > attend the perl meeting. > > Can someone pass around a sign-in sheet and maybe make some notes on > the general topics discussed? > > > Thanks! > > > Daniel > _______________________________________________ > Thousand-oaks-pm mailing list > Thousand-oaks-pm at pm.org > http://mail.pm.org/mailman/listinfo/thousand-oaks-pm