From madcityzen at gmail.com Wed Nov 4 22:51:11 2015 From: madcityzen at gmail.com (Doug Bell) Date: Thu, 5 Nov 2015 00:51:11 -0600 Subject: [Chicago-talk] Holiday Meetings - Monk's Pub; Venue needed Message-ID: <937D2510-68C9-4958-9690-16CA161D58AF@gmail.com> As we go into the holiday season, we are in need of a new venue to hold our meetings. If anyone has some meeting space, let me know. In lieu of an office hours, there will be an informal social get-together at Monk's Pub (http://www.monkspubchicago.com ), Thursday November 5 (tomorrow) at 7:00pm. brian d foy, author of several Perl books, numerous CPAN modules, and founder of the Perl Mongers groups, is in town. So come down, have a few drinks, and talk about Perl! Doug Bell madcityzen at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From gatorreina at gmail.com Thu Nov 5 05:05:26 2015 From: gatorreina at gmail.com (Richard Reina) Date: Thu, 5 Nov 2015 07:05:26 -0600 Subject: [Chicago-talk] Holiday Meetings - Monk's Pub; Venue needed In-Reply-To: <937D2510-68C9-4958-9690-16CA161D58AF@gmail.com> References: <937D2510-68C9-4958-9690-16CA161D58AF@gmail.com> Message-ID: In town? I though Brian D Foy lived in Chicago? 2015-11-05 0:51 GMT-06:00 Doug Bell : > As we go into the holiday season, we are in need of a new venue to hold > our meetings. If anyone has some meeting space, let me know. > > In lieu of an office hours, there will be an informal social get-together > at Monk's Pub (http://www.monkspubchicago.com), Thursday November 5 > (tomorrow) at 7:00pm. brian d foy, author of several Perl books, numerous > CPAN modules, and founder of the Perl Mongers groups, is in town. > > So come down, have a few drinks, and talk about Perl! > > Doug Bell > madcityzen at gmail.com > > > > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.a.berger at gmail.com Thu Nov 5 07:02:23 2015 From: joel.a.berger at gmail.com (Joel Berger) Date: Thu, 05 Nov 2015 15:02:23 +0000 Subject: [Chicago-talk] Holiday Meetings - Monk's Pub; Venue needed In-Reply-To: References: <937D2510-68C9-4958-9690-16CA161D58AF@gmail.com> Message-ID: He moved to New York a few years back. He's only in town for a couple days here and there at this point. On Thu, Nov 5, 2015 at 7:05 AM Richard Reina wrote: > In town? I though Brian D Foy lived in Chicago? > > 2015-11-05 0:51 GMT-06:00 Doug Bell : > >> As we go into the holiday season, we are in need of a new venue to hold >> our meetings. If anyone has some meeting space, let me know. >> >> In lieu of an office hours, there will be an informal social get-together >> at Monk's Pub (http://www.monkspubchicago.com), Thursday November 5 >> (tomorrow) at 7:00pm. brian d foy, author of several Perl books, numerous >> CPAN modules, and founder of the Perl Mongers groups, is in town. >> >> So come down, have a few drinks, and talk about Perl! >> >> Doug Bell >> madcityzen at gmail.com >> >> >> >> >> _______________________________________________ >> Chicago-talk mailing list >> Chicago-talk at pm.org >> http://mail.pm.org/mailman/listinfo/chicago-talk >> > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk -------------- next part -------------- An HTML attachment was scrubbed... URL: From richard at rushlogistics.com Thu Nov 5 07:11:18 2015 From: richard at rushlogistics.com (Richard Reina) Date: Thu, 5 Nov 2015 09:11:18 -0600 Subject: [Chicago-talk] Holiday Meetings - Monk's Pub; Venue needed In-Reply-To: References: <937D2510-68C9-4958-9690-16CA161D58AF@gmail.com> Message-ID: Sorry I'll miss out. Have to take my daughter to softball practice. > El 5 nov 2015, a las 9:02 AM, Joel Berger escribi?: > > He moved to New York a few years back. He's only in town for a couple days here and there at this point. > >> On Thu, Nov 5, 2015 at 7:05 AM Richard Reina wrote: >> In town? I though Brian D Foy lived in Chicago? >> >> 2015-11-05 0:51 GMT-06:00 Doug Bell : >>> As we go into the holiday season, we are in need of a new venue to hold our meetings. If anyone has some meeting space, let me know. >>> >>> In lieu of an office hours, there will be an informal social get-together at Monk's Pub (http://www.monkspubchicago.com), Thursday November 5 (tomorrow) at 7:00pm. brian d foy, author of several Perl books, numerous CPAN modules, and founder of the Perl Mongers groups, is in town. >>> >>> So come down, have a few drinks, and talk about Perl! >>> >>> Doug Bell >>> madcityzen at gmail.com >>> >>> >>> >>> >>> _______________________________________________ >>> Chicago-talk mailing list >>> Chicago-talk at pm.org >>> http://mail.pm.org/mailman/listinfo/chicago-talk >> >> _______________________________________________ >> Chicago-talk mailing list >> Chicago-talk at pm.org >> http://mail.pm.org/mailman/listinfo/chicago-talk > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk -------------- next part -------------- An HTML attachment was scrubbed... URL: From zelein at gmail.com Thu Nov 5 08:59:23 2015 From: zelein at gmail.com (Brian Mielke) Date: Thu, 5 Nov 2015 10:59:23 -0600 Subject: [Chicago-talk] Holiday Meetings - Monk's Pub; Venue needed In-Reply-To: <937D2510-68C9-4958-9690-16CA161D58AF@gmail.com> References: <937D2510-68C9-4958-9690-16CA161D58AF@gmail.com> Message-ID: <7DA51211-BAAB-48A6-B66C-1AFDB014672F@gmail.com> I will see you at monks. Thank you, Brian Mielke > On Nov 5, 2015, at 00:51, Doug Bell wrote: > > As we go into the holiday season, we are in need of a new venue to hold our meetings. If anyone has some meeting space, let me know. > > In lieu of an office hours, there will be an informal social get-together at Monk's Pub (http://www.monkspubchicago.com), Thursday November 5 (tomorrow) at 7:00pm. brian d foy, author of several Perl books, numerous CPAN modules, and founder of the Perl Mongers groups, is in town. > > So come down, have a few drinks, and talk about Perl! > > Doug Bell > madcityzen at gmail.com > > > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk -------------- next part -------------- An HTML attachment was scrubbed... URL: From zelein at gmail.com Thu Nov 5 12:26:39 2015 From: zelein at gmail.com (Brian Mielke) Date: Thu, 5 Nov 2015 14:26:39 -0600 Subject: [Chicago-talk] Holiday Meetings - Monk's Pub; Venue needed In-Reply-To: <7DA51211-BAAB-48A6-B66C-1AFDB014672F@gmail.com> References: <937D2510-68C9-4958-9690-16CA161D58AF@gmail.com> <7DA51211-BAAB-48A6-B66C-1AFDB014672F@gmail.com> Message-ID: I work around the corner from Monks. I'll see you there tonight. On Thu, Nov 5, 2015 at 10:59 AM, Brian Mielke wrote: > I will see you at monks. > > Thank you, > > Brian Mielke > > On Nov 5, 2015, at 00:51, Doug Bell wrote: > > As we go into the holiday season, we are in need of a new venue to hold > our meetings. If anyone has some meeting space, let me know. > > In lieu of an office hours, there will be an informal social get-together > at Monk's Pub (http://www.monkspubchicago.com), Thursday November 5 > (tomorrow) at 7:00pm. brian d foy, author of several Perl books, numerous > CPAN modules, and founder of the Perl Mongers groups, is in town. > > So come down, have a few drinks, and talk about Perl! > > Doug Bell > madcityzen at gmail.com > > > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From richard at rushlogistics.com Mon Nov 23 08:10:41 2015 From: richard at rushlogistics.com (richard at rushlogistics.com) Date: Mon, 23 Nov 2015 10:10:41 -0600 Subject: [Chicago-talk] Combine like hash elements Message-ID: <20151123101041.5shga4s5s8ggcwgw@hostingemail.xo.com> I have a hash reference with the following structure: { '11' => {'AMOUNT' => '20.00','ID' => '11','NAME' => 'Lincoln Park'}, '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, '13' => {'AMOUNT' => '41.00','ID' => '12','NAME' => 'Lincoln Park'} } Can anyone tell me how I can combine them by 'NAME' so that I would have: { '11' => {'AMOUNT' => '61.00','ID' => '11','NAME' => 'Lincoln Park'}, '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, } Thanks From shawn.c.carroll at gmail.com Mon Nov 23 08:17:39 2015 From: shawn.c.carroll at gmail.com (Shawn Carroll) Date: Mon, 23 Nov 2015 10:17:39 -0600 Subject: [Chicago-talk] Combine like hash elements In-Reply-To: <20151123101041.5shga4s5s8ggcwgw@hostingemail.xo.com> References: <20151123101041.5shga4s5s8ggcwgw@hostingemail.xo.com> Message-ID: At the risk of sounding like StackOverflow, what have you tried? shawn.c.carroll at gmail.com Software Engineer Soccer Referee On Mon, Nov 23, 2015 at 10:10 AM, wrote: > I have a hash reference with the following structure: > > { > '11' => {'AMOUNT' => '20.00','ID' => '11','NAME' => 'Lincoln Park'}, > '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, > '13' => {'AMOUNT' => '41.00','ID' => '12','NAME' => 'Lincoln Park'} > } > > Can anyone tell me how I can combine them by 'NAME' so that I would have: > > { > '11' => {'AMOUNT' => '61.00','ID' => '11','NAME' => 'Lincoln Park'}, > '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, > } > > Thanks > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From richard at rushlogistics.com Mon Nov 23 08:36:18 2015 From: richard at rushlogistics.com (richard at rushlogistics.com) Date: Mon, 23 Nov 2015 10:36:18 -0600 Subject: [Chicago-talk] Combine like hash elements In-Reply-To: References: <20151123101041.5shga4s5s8ggcwgw@hostingemail.xo.com> Message-ID: <20151123103618.uyxoyjqa74go88ww@hostingemail.xo.com> Did not include it because it did not come close but if you must see it here it is: ? ?%$w_ref = sort { %$w_ref{$a} %$w_ref{$b} } keys %$w_ref; On Mon, 23 Nov 2015 10:17:39 -0600, Shawn Carroll wrote: At the risk of sounding like StackOverflow, what have you tried? shawn.c.carroll at gmail.com Software Engineer Soccer Referee On Mon, Nov 23, 2015 at 10:10 AM, wrote: I have a hash reference with the following structure: { '11' => {'AMOUNT' => '20.00','ID' => '11','NAME' => 'Lincoln Park'}, '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, '13' => {'AMOUNT' => '41.00','ID' => '12','NAME' => 'Lincoln Park'} } Can anyone tell me how I can combine them by 'NAME' so that I would have: { '11' => {'AMOUNT' => '61.00','ID' => '11','NAME' => 'Lincoln Park'}, '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, } Thanks _______________________________________________ Chicago-talk mailing list Chicago-talk at pm.org http://mail.pm.org/mailman/listinfo/chicago-talk ------------------------- _______________________________________________ Chicago-talk mailing list Chicago-talk at pm.org http://mail.pm.org/mailman/listinfo/chicago-talk -------------- next part -------------- An HTML attachment was scrubbed... URL: From andy at petdance.com Mon Nov 23 08:38:42 2015 From: andy at petdance.com (Andy Lester) Date: Mon, 23 Nov 2015 10:38:42 -0600 Subject: [Chicago-talk] Combine like hash elements In-Reply-To: <20151123103618.uyxoyjqa74go88ww@hostingemail.xo.com> References: <20151123101041.5shga4s5s8ggcwgw@hostingemail.xo.com> <20151123103618.uyxoyjqa74go88ww@hostingemail.xo.com> Message-ID: <0C3EC03F-8541-4BEB-AD7A-2661F7933327@petdance.com> > { > '11' => {'AMOUNT' => '20.00','ID' => '11','NAME' => 'Lincoln Park'}, > '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, > '13' => {'AMOUNT' => '41.00','ID' => '12','NAME' => 'Lincoln Park'} > } > > Can anyone tell me how I can combine them by 'NAME' so that I would have: > > { > '11' => {'AMOUNT' => '61.00','ID' => '11','NAME' => 'Lincoln Park'}, > '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, > } > On Nov 23, 2015, at 10:36 AM, richard at rushlogistics.com wrote: > > Did not include it because it did not come close but if you must see it here it is: > > %$w_ref = sort { %$w_ref{$a} <=> %$w_ref{$b} } keys %$w_ref; What that?s doing is sorting. There?s no combining going on. You?re going to need to write something that goes through your hash values and finds the ones that have the same name and add the AMOUNTs together. -- Andy Lester => www.petdance.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From amead2 at alanmead.org Mon Nov 23 08:40:54 2015 From: amead2 at alanmead.org (Alan Mead) Date: Mon, 23 Nov 2015 10:40:54 -0600 Subject: [Chicago-talk] Combine like hash elements In-Reply-To: <20151123101041.5shga4s5s8ggcwgw@hostingemail.xo.com> References: <20151123101041.5shga4s5s8ggcwgw@hostingemail.xo.com> Message-ID: <56534196.8020207@alanmead.org> Richard, So, you want the new hash to have fewer elements. There may be an idiomatic way, but the straightforward way would be to cycle through your old hash building a new hash of totals. Let's say your hash is %trans, then: my %total_trans; for my $k ( keys %trans) { my $name = $$trans{$k}->{'NAME'}; # check if this is right my $amount = $$trans{$k}->{'AMOUNT'}; # check if this is right $total_trans{$name} += $amount; } printf "%.2f\n", $total_trans{'Lincoln Park'}; # prints 38.00 You'll have to check the two temporary variables to ensure I dereferenced them correctly and then you could factor them out. You could modify this so the new hash has the same structure as the old hash. I think this would be clearer than trying to edit the original hash. Pity your data are not in a database where this would be a simple database call. -Alan On 11/23/2015 10:10 AM, richard at rushlogistics.com wrote: > I have a hash reference with the following structure: > > { > '11' => {'AMOUNT' => '20.00','ID' => '11','NAME' => 'Lincoln Park'}, > '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, > '13' => {'AMOUNT' => '41.00','ID' => '12','NAME' => 'Lincoln Park'} > } > > Can anyone tell me how I can combine them by 'NAME' so that I would have: > > { > '11' => {'AMOUNT' => '61.00','ID' => '11','NAME' => 'Lincoln Park'}, > '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, > } > > Thanks > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk -- Alan D. Mead, Ph.D. President, Talent Algorithms Inc. science + technology = better workers +815.588.3846 (Office) +267.334.4143 (Mobile) http://www.alanmead.org Announcing the Journal of Computerized Adaptive Testing (JCAT), a peer-reviewed electronic journal designed to advance the science and practice of computerized adaptive testing: http://www.iacat.org/jcat From imranjj at gmail.com Mon Nov 23 08:46:41 2015 From: imranjj at gmail.com (imran javaid) Date: Mon, 23 Nov 2015 10:46:41 -0600 Subject: [Chicago-talk] Combine like hash elements In-Reply-To: <0C3EC03F-8541-4BEB-AD7A-2661F7933327@petdance.com> References: <20151123101041.5shga4s5s8ggcwgw@hostingemail.xo.com> <20151123103618.uyxoyjqa74go88ww@hostingemail.xo.com> <0C3EC03F-8541-4BEB-AD7A-2661F7933327@petdance.com> Message-ID: I am guessing there is a typo in the sample input data. In the third entry, isn't the key and ID value supposed to be the same? Is it supposed to be 11 or 13? If it is the way it is or if it really is 13, then you need to arbitrate which key and/or ID the resulting hash will have. { '11' => {'AMOUNT' => '20.00','ID' => '11','NAME' => 'Lincoln Park'}, '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, '13' => {'AMOUNT' => '41.00','ID' => '12','NAME' => 'Lincoln Park'} } On Mon, Nov 23, 2015 at 10:38 AM, Andy Lester wrote: > { > >> '11' => {'AMOUNT' => '20.00','ID' => '11','NAME' => 'Lincoln Park'}, >> '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, >> '13' => {'AMOUNT' => '41.00','ID' => '12','NAME' => 'Lincoln Park'} >> } >> >> Can anyone tell me how I can combine them by 'NAME' so that I would have: >> >> { >> '11' => {'AMOUNT' => '61.00','ID' => '11','NAME' => 'Lincoln Park'}, >> '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, >> } >> > > On Nov 23, 2015, at 10:36 AM, richard at rushlogistics.com wrote: > > Did not include it because it did not come close but if you must see it > here it is: > > > %$w_ref = sort { %$w_ref{$a} <=> %$w_ref{$b} } keys %$w_ref; > > > What that?s doing is sorting. There?s no combining going on. You?re > going to need to write something that goes through your hash values and > finds the ones that have the same name and add the AMOUNTs together. > > > -- > Andy Lester => www.petdance.com > > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.a.berger at gmail.com Mon Nov 23 08:54:59 2015 From: joel.a.berger at gmail.com (Joel Berger) Date: Mon, 23 Nov 2015 16:54:59 +0000 Subject: [Chicago-talk] Combine like hash elements In-Reply-To: References: <20151123101041.5shga4s5s8ggcwgw@hostingemail.xo.com> <20151123103618.uyxoyjqa74go88ww@hostingemail.xo.com> <0C3EC03F-8541-4BEB-AD7A-2661F7933327@petdance.com> Message-ID: A quick attempt (without preserving the ids which are ambiguous as imran said): my %totals; $totals{$_->{NAME}} += $_->{AMOUNT} for values %$orig; On Mon, Nov 23, 2015 at 10:46 AM imran javaid wrote: > I am guessing there is a typo in the sample input data. In the third > entry, isn't the key and ID value supposed to be the same? Is it supposed > to be 11 or 13? If it is the way it is or if it really is 13, then you need > to arbitrate which key and/or ID the resulting hash will have. > > { > '11' => {'AMOUNT' => '20.00','ID' => '11','NAME' => 'Lincoln Park'}, > '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, > '13' => {'AMOUNT' => '41.00','ID' => '12','NAME' => 'Lincoln Park'} > } > > > On Mon, Nov 23, 2015 at 10:38 AM, Andy Lester wrote: > >> { >> >>> '11' => {'AMOUNT' => '20.00','ID' => '11','NAME' => 'Lincoln Park'}, >>> '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, >>> '13' => {'AMOUNT' => '41.00','ID' => '12','NAME' => 'Lincoln Park'} >>> } >>> >>> Can anyone tell me how I can combine them by 'NAME' so that I would have: >>> >>> { >>> '11' => {'AMOUNT' => '61.00','ID' => '11','NAME' => 'Lincoln Park'}, >>> '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, >>> } >>> >> >> On Nov 23, 2015, at 10:36 AM, richard at rushlogistics.com wrote: >> >> Did not include it because it did not come close but if you must see it >> here it is: >> >> >> %$w_ref = sort { %$w_ref{$a} <=> %$w_ref{$b} } keys %$w_ref; >> >> >> What that?s doing is sorting. There?s no combining going on. You?re >> going to need to write something that goes through your hash values and >> finds the ones that have the same name and add the AMOUNTs together. >> >> >> -- >> Andy Lester => www.petdance.com >> >> >> _______________________________________________ >> Chicago-talk mailing list >> Chicago-talk at pm.org >> http://mail.pm.org/mailman/listinfo/chicago-talk >> > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk -------------- next part -------------- An HTML attachment was scrubbed... URL: From lembark at wrkhors.com Mon Nov 23 09:33:44 2015 From: lembark at wrkhors.com (Steven Lembark) Date: Mon, 23 Nov 2015 11:33:44 -0600 Subject: [Chicago-talk] Combine like hash elements In-Reply-To: <20151123112840.148986cc@cannibal> References: <20151123101041.5shga4s5s8ggcwgw@hostingemail.xo.com> <20151123112840.148986cc@cannibal> Message-ID: <20151123113344.27545b39@cannibal> My apologies: First step should've been search.cpan.org. Thought of this after I'd hit send. -- Steven Lembark 3646 Flora Pl Workhorse Computing St Louis, MO 63110 lembark at wrkhors.com +1 888 359 3508 From lembark at wrkhors.com Mon Nov 23 09:28:40 2015 From: lembark at wrkhors.com (Steven Lembark) Date: Mon, 23 Nov 2015 11:28:40 -0600 Subject: [Chicago-talk] Combine like hash elements In-Reply-To: <20151123101041.5shga4s5s8ggcwgw@hostingemail.xo.com> References: <20151123101041.5shga4s5s8ggcwgw@hostingemail.xo.com> Message-ID: <20151123112840.148986cc@cannibal> On Mon, 23 Nov 2015 10:10:41 -0600 richard at rushlogistics.com wrote: > I have a hash reference with the following structure: > > { > '11' => {'AMOUNT' => '20.00','ID' => '11','NAME' => 'Lincoln Park'}, > '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, > '13' => {'AMOUNT' => '41.00','ID' => '12','NAME' => 'Lincoln Park'} > } > > Can anyone tell me how I can combine them by 'NAME' so that I would have: > > { > '11' => {'AMOUNT' => '61.00','ID' => '11','NAME' => 'Lincoln Park'}, > '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, > } You don't seem to care about the keys (loosing key "13" wasn't a problem). Q: Are the ID values important or could they be discarded? If so then just make a new hash keyed by NAME and accumulate the AMOUNT values: my %resultz = (); for( values %inputz ) { my ( $name, $amt, $id ) = @{ $_ }{ qw( NAME AMOUNT ID ) }; my $val = $resultz{ $name } ||= { ID => $id, NAME => $name }; $val->{ AMOUNT } += $amt; } # at this point %resultz is keyed by name with an id and amount # for each entry. %inputz = (); while( my ( $name, $val ) = each %resultz ) { $inputz{ $val->{ ID } } = $val; } # at this point the original inputs hash is keyed by ID # with values having a name, accumulated amount, and id. # multiple id's are collapsed into a single ID with the # value of the first record for that name. -- Steven Lembark 3646 Flora Pl Workhorse Computing St Louis, MO 63110 lembark at wrkhors.com +1 888 359 3508 From richard at rushlogistics.com Mon Nov 23 10:52:10 2015 From: richard at rushlogistics.com (richard at rushlogistics.com) Date: Mon, 23 Nov 2015 12:52:10 -0600 Subject: [Chicago-talk] Combine like hash elements In-Reply-To: <20151123112840.148986cc@cannibal> References: <20151123101041.5shga4s5s8ggcwgw@hostingemail.xo.com> <20151123112840.148986cc@cannibal> Message-ID: <20151123125210.sdid5g9pj404c8k8@hostingemail.xo.com> Hello Everybody, ? Thank you for all the replies. The ID field did not need to be preserved. However, I was having difficulty conceptualizing the manipulation of the hash so I decided to use DBI->bind_colums instead and iterate throught the values in a way that I found at least a bit more clear. Still working on cleaning this up but this is at least the direction that I am going in. ? Thanks again for the help. ? ?? my ($DID, $AMOUNT, $NAME,); ??? $sth->bind_columns(\($DID, $AMOUNT, $NAME)); my $lastN; my $lastA; my @CAMS; my $keepN; my $keepA; while ($sth->fetch) { ? if ($lastN) { ??? ??? if ($NAME eq $lastN) { ??? #print "Combine $AMOUNT, $NAME\n"; ??? $keepA = $AMOUNT + $lastA; ??? $keepN = $NAME; ??? ??? } else { ??? $keepA = $AMOUNT; ??? $keepN = $NAME; ??? } } # print "$DID, $AMOUNT, $NAME\n"; $lastN = $NAME; $lastA = $AMOUNT; push(@CAMS, $keepA . " " . $keepN); } On Mon, 23 Nov 2015 11:28:40 -0600, Steven Lembark wrote: On Mon, 23 Nov 2015 10:10:41 -0600 richard at rushlogistics.com wrote: > I have a hash reference with the following structure: > > { > '11' => {'AMOUNT' => '20.00','ID' => '11','NAME' => 'Lincoln Park'}, > '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, > '13' => {'AMOUNT' => '41.00','ID' => '12','NAME' => 'Lincoln Park'} > } > > Can anyone tell me how I can combine them by 'NAME' so that I would have: > > { > '11' => {'AMOUNT' => '61.00','ID' => '11','NAME' => 'Lincoln Park'}, > '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, > } You don't seem to care about the keys (loosing key "13" wasn't a problem). Q: Are the ID values important or could they be discarded? If so then just make a new hash keyed by NAME and accumulate the AMOUNT values: my %resultz = (); for( values %inputz ) { my ( $name, $amt, $id ) = @{ $_ }{ qw( NAME AMOUNT ID ) }; my $val = $resultz{ $name } ||= { ID => $id, NAME => $name }; $val->{ AMOUNT } += $amt; } # at this point %resultz is keyed by name with an id and amount # for each entry. %inputz = (); while( my ( $name, $val ) = each %resultz ) { $inputz{ $val->{ ID } } = $val; } # at this point the original inputs hash is keyed by ID # with values having a name, accumulated amount, and id. # multiple id's are collapsed into a single ID with the # value of the first record for that name. -- Steven Lembark 3646 Flora Pl Workhorse Computing St Louis, MO 63110 lembark at wrkhors.com +1 888 359 3508 _______________________________________________ Chicago-talk mailing list Chicago-talk at pm.org http://mail.pm.org/mailman/listinfo/chicago-talk -------------- next part -------------- An HTML attachment was scrubbed... URL: From imranjj at gmail.com Mon Nov 23 10:55:13 2015 From: imranjj at gmail.com (imran javaid) Date: Mon, 23 Nov 2015 12:55:13 -0600 Subject: [Chicago-talk] Combine like hash elements In-Reply-To: <20151123125210.sdid5g9pj404c8k8@hostingemail.xo.com> References: <20151123101041.5shga4s5s8ggcwgw@hostingemail.xo.com> <20151123112840.148986cc@cannibal> <20151123125210.sdid5g9pj404c8k8@hostingemail.xo.com> Message-ID: You could also push the aggregation to the DB server and have it do the sum by name. On Mon, Nov 23, 2015 at 12:52 PM, wrote: > Hello Everybody, > > > > Thank you for all the replies. The ID field did not need to be preserved. > However, I was having difficulty conceptualizing the manipulation of the > hash so I decided to use DBI->bind_colums instead and iterate throught the > values in a way that I found at least a bit more clear. Still working on > cleaning this up but this is at least the direction that I am going in. > > > > Thanks again for the help. > > > > my ($DID, $AMOUNT, $NAME,); > $sth->bind_columns(\($DID, $AMOUNT, $NAME)); > > my $lastN; > my $lastA; > my @CAMS; > my $keepN; > my $keepA; > > while ($sth->fetch) { > > if ($lastN) { > > if ($NAME eq $lastN) { > > #print "Combine $AMOUNT, $NAME\n"; > $keepA = $AMOUNT + $lastA; > $keepN = $NAME; > > } else { > > $keepA = $AMOUNT; > $keepN = $NAME; > > } > > } > > # print "$DID, $AMOUNT, $NAME\n"; > > $lastN = $NAME; > $lastA = $AMOUNT; > > push(@CAMS, $keepA . " " . $keepN); > > > } > > > On Mon, 23 Nov 2015 11:28:40 -0600, Steven Lembark > wrote: > > On Mon, 23 Nov 2015 10:10:41 -0600 > richard at rushlogistics.com wrote: > > > I have a hash reference with the following structure: > > > > { > > '11' => {'AMOUNT' => '20.00','ID' => '11','NAME' => 'Lincoln Park'}, > > '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, > > '13' => {'AMOUNT' => '41.00','ID' => '12','NAME' => 'Lincoln Park'} > > } > > > > Can anyone tell me how I can combine them by 'NAME' so that I would have: > > > > { > > '11' => {'AMOUNT' => '61.00','ID' => '11','NAME' => 'Lincoln Park'}, > > '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, > > } > > You don't seem to care about the keys (loosing key "13" wasn't > a problem). > > Q: Are the ID values important or could they be discarded? > > If so then just make a new hash keyed by NAME and accumulate > the AMOUNT values: > > my %resultz = (); > > for( values %inputz ) > { > my ( $name, $amt, $id ) = @{ $_ }{ qw( NAME AMOUNT ID ) }; > my $val > = $resultz{ $name } ||= { ID => $id, NAME => $name }; > > $val->{ AMOUNT } += $amt; > } > > # at this point %resultz is keyed by name with an id and amount > # for each entry. > > %inputz = (); > > while( my ( $name, $val ) = each %resultz ) > { > $inputz{ $val->{ ID } } = $val; > } > > # at this point the original inputs hash is keyed by ID > # with values having a name, accumulated amount, and id. > # multiple id's are collapsed into a single ID with the > # value of the first record for that name. > > -- > Steven Lembark 3646 Flora Pl > Workhorse Computing St Louis, MO 63110 > lembark at wrkhors.com +1 888 359 3508 > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > > > > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.limardo at forwardphase.com Mon Nov 23 13:46:21 2015 From: joel.limardo at forwardphase.com (Joel Limardo) Date: Mon, 23 Nov 2015 15:46:21 -0600 Subject: [Chicago-talk] Combine like hash elements In-Reply-To: References: <20151123101041.5shga4s5s8ggcwgw@hostingemail.xo.com> <20151123112840.148986cc@cannibal> <20151123125210.sdid5g9pj404c8k8@hostingemail.xo.com> Message-ID: I disagree that this should be put in a database unless you have sufficient values to warrant that. If you are dealing with just a few dozen values relying upon a database to essentially sort a hash is not very Perl-ish I think. At any rate, here is a more verbose example that uses Data::Dumper. The other examples provided before should be better, but I offer this because you can debug it and see what is happening line by line: use strict; use Data::Dumper; my $targetRef; my $hashRef = { '11' => {'AMOUNT' => '20.00','ID' => '11','NAME' => 'Lincoln Park'}, '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, '13' => {'AMOUNT' => '41.00','ID' => '11','NAME' => 'Lincoln Park'} }; #ID on line 3 fixed to match first line id foreach my $structId(keys %$hashRef) { my $struct = $hashRef->{$structId}; if (!$targetRef->{$struct->{'ID'}}){ $targetRef->{$struct->{'ID'}} = { 'NAME' => $struct->{'NAME'}, 'ID' => $struct->{'ID'}, 'AMOUNT'=> $struct->{'AMOUNT'} }; } else { $targetRef->{$struct->{'ID'}}->{'AMOUNT'} += $struct->{'AMOUNT'}; } } print Dumper $targetRef; 1; == produces == $VAR1 = { '12' => { 'ID' => '12', 'AMOUNT' => '38.00', 'NAME' => 'Bucktown' }, '11' => { 'NAME' => 'Lincoln Park', 'AMOUNT' => '61', 'ID' => '11' } }; On Mon, Nov 23, 2015 at 12:55 PM, imran javaid wrote: > You could also push the aggregation to the DB server and have it do the > sum by name. > > On Mon, Nov 23, 2015 at 12:52 PM, wrote: > >> Hello Everybody, >> >> >> >> Thank you for all the replies. The ID field did not need to be preserved. >> However, I was having difficulty conceptualizing the manipulation of the >> hash so I decided to use DBI->bind_colums instead and iterate throught the >> values in a way that I found at least a bit more clear. Still working on >> cleaning this up but this is at least the direction that I am going in. >> >> >> >> Thanks again for the help. >> >> >> >> my ($DID, $AMOUNT, $NAME,); >> $sth->bind_columns(\($DID, $AMOUNT, $NAME)); >> >> my $lastN; >> my $lastA; >> my @CAMS; >> my $keepN; >> my $keepA; >> >> while ($sth->fetch) { >> >> if ($lastN) { >> >> if ($NAME eq $lastN) { >> >> #print "Combine $AMOUNT, $NAME\n"; >> $keepA = $AMOUNT + $lastA; >> $keepN = $NAME; >> >> } else { >> >> $keepA = $AMOUNT; >> $keepN = $NAME; >> >> } >> >> } >> >> # print "$DID, $AMOUNT, $NAME\n"; >> >> $lastN = $NAME; >> $lastA = $AMOUNT; >> >> push(@CAMS, $keepA . " " . $keepN); >> >> >> } >> >> >> On Mon, 23 Nov 2015 11:28:40 -0600, Steven Lembark >> wrote: >> >> On Mon, 23 Nov 2015 10:10:41 -0600 >> richard at rushlogistics.com wrote: >> >> > I have a hash reference with the following structure: >> > >> > { >> > '11' => {'AMOUNT' => '20.00','ID' => '11','NAME' => 'Lincoln Park'}, >> > '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, >> > '13' => {'AMOUNT' => '41.00','ID' => '12','NAME' => 'Lincoln Park'} >> > } >> > >> > Can anyone tell me how I can combine them by 'NAME' so that I would >> have: >> > >> > { >> > '11' => {'AMOUNT' => '61.00','ID' => '11','NAME' => 'Lincoln Park'}, >> > '12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'}, >> > } >> >> You don't seem to care about the keys (loosing key "13" wasn't >> a problem). >> >> Q: Are the ID values important or could they be discarded? >> >> If so then just make a new hash keyed by NAME and accumulate >> the AMOUNT values: >> >> my %resultz = (); >> >> for( values %inputz ) >> { >> my ( $name, $amt, $id ) = @{ $_ }{ qw( NAME AMOUNT ID ) }; >> my $val >> = $resultz{ $name } ||= { ID => $id, NAME => $name }; >> >> $val->{ AMOUNT } += $amt; >> } >> >> # at this point %resultz is keyed by name with an id and amount >> # for each entry. >> >> %inputz = (); >> >> while( my ( $name, $val ) = each %resultz ) >> { >> $inputz{ $val->{ ID } } = $val; >> } >> >> # at this point the original inputs hash is keyed by ID >> # with values having a name, accumulated amount, and id. >> # multiple id's are collapsed into a single ID with the >> # value of the first record for that name. >> >> -- >> Steven Lembark 3646 Flora Pl >> Workhorse Computing St Louis, MO 63110 >> lembark at wrkhors.com +1 888 359 3508 >> _______________________________________________ >> Chicago-talk mailing list >> Chicago-talk at pm.org >> http://mail.pm.org/mailman/listinfo/chicago-talk >> >> >> >> >> _______________________________________________ >> Chicago-talk mailing list >> Chicago-talk at pm.org >> http://mail.pm.org/mailman/listinfo/chicago-talk >> > > > _______________________________________________ > Chicago-talk mailing list > Chicago-talk at pm.org > http://mail.pm.org/mailman/listinfo/chicago-talk > -- Sincerely, Joel Limardo -------------- next part -------------- An HTML attachment was scrubbed... URL: