<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" data-hsystem="true"></head>
<body><style>p{margin: 0;padding: 0;}

</style>
<p>Hello Everybody,</p>
<p> </p>
<p>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.</p>
<p> </p>
<p>Thanks again for the help.</p>
<p> </p>
<p>   my ($DID, $AMOUNT, $NAME,);<br>    $sth->bind_columns(\($DID,
$AMOUNT, $NAME));<br><br>my $lastN;<br>my $lastA;<br>my @CAMS;<br>my
$keepN;<br>my $keepA;<br><br>while ($sth->fetch) {<br> <br>if ($lastN) {
<br>    <br>    if ($NAME eq $lastN) {<br><br>    #print "Combine
$AMOUNT, $NAME\n";<br>    $keepA = $AMOUNT + $lastA;<br>    $keepN =
$NAME;<br>    <br>    } else {<br><br>    $keepA = $AMOUNT;<br>   
$keepN = $NAME;<br><br>    }<br><br>} <br><br># print "$DID, $AMOUNT,
$NAME\n";<br><br>$lastN = $NAME;<br>$lastA = $AMOUNT;<br><br>push(@CAMS, $keepA
. " " . $keepN);<br><br>}<br><br><br>On Mon, 23 Nov 2015 11:28:40 -0600, Steven
Lembark <lembark@wrkhors.com> wrote:</p>
<blockquote style="border-left: 2px solid #000000; padding-right: 0px;
padding-left: 5px; margin-left: 5px; margin-right: 0px;">On Mon, 23 Nov 2015
10:10:41 -0600<br> richard@rushlogistics.com wrote:<br><br> > I have a hash
reference with the following structure:<br> > <br> > {<br> > '11' =>
{'AMOUNT' => '20.00','ID' => '11','NAME' => 'Lincoln Park'},<br> >
'12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'},<br>
> '13' => {'AMOUNT' => '41.00','ID' => '12','NAME' => 'Lincoln
Park'}<br> > }<br> > <br> > Can anyone tell me how I can combine them
by 'NAME' so that I would have:<br> > <br> > {<br> > '11' =>
{'AMOUNT' => '61.00','ID' => '11','NAME' => 'Lincoln Park'},<br> >
'12' => {'AMOUNT' => '38.00','ID' => '12','NAME' => 'Bucktown'},<br>
> }<br><br> You don't seem to care about the keys (loosing key "13"
wasn't<br> a problem). <br><br> Q: Are the ID values important or could they be
discarded?<br><br> If so then just make a new hash keyed by NAME and
accumulate<br> the AMOUNT values:<br><br> my %resultz = ();<br><br> for( values
%inputz )<br> {<br> my ( $name, $amt, $id ) = @{ $_ }{ qw( NAME AMOUNT ID )
};<br> my $val<br> = $resultz{ $name } ||= { ID => $id, NAME => $name
};<br><br> $val->{ AMOUNT } += $amt;<br> }<br><br> # at this point %resultz
is keyed by name with an id and amount<br> # for each entry.<br><br> %inputz =
();<br><br> while( my ( $name, $val ) = each %resultz )<br> {<br> $inputz{
$val->{ ID } } = $val;<br> }<br><br> # at this point the original inputs hash
is keyed by ID<br> # with values having a name, accumulated amount, and id.<br>
# multiple id's are collapsed into a single ID with the <br> # value of the
first record for that name.<br><br> -- <br> Steven Lembark 3646 Flora Pl<br>
Workhorse Computing St Louis, MO 63110<br> lembark@wrkhors.com +1 888 359
3508<br> _______________________________________________<br> Chicago-talk
mailing list<br> Chicago-talk@pm.org<br>
http://mail.pm.org/mailman/listinfo/chicago-talk<br>
</blockquote>
<p><br><br></p>

</body>
</html>