--As of Tuesday, April 27, 2004 8:30 AM -0700, Christopher Lyon is alleged to have said:

while ( @array = $sth->fetchrow_array() ) {
        print "$array[1] -> $array[3]\n";
        $table{ "$array[1]" } = "$array[3]";
}

my @keys = keys( %table ) ;
while ( $key = pop( @keys ) ) {
        print "$key=>$table{ $key }|\n";
}

So, I guess I am inserting because I end up with like this:

I end up with this from a hash.
widget-c=>10|
widget-b=>20|
widget-a=>20|


So, how would I add in the values? It looks like I am replacing them.

--As for the rest, it is mine.


Replace:
$table{ "$array[1]" } = "$array[3]";

with:
$table{ $array[1] } += $array[3];

or (equivalent, but more clear):
$table{ $array[1] } =  $table{ $array[1] } + $array[3];

(Note that you don't need the quotes in the first line.)

Daniel T. Staal

---------------------------------------------------------------
This email copyright the author.  Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes.  This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---------------------------------------------------------------

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to