> -----Original Message-----
> From: Daniel Staal [mailto:[EMAIL PROTECTED]
> Sent: Monday, April 26, 2004 8:54 PM
> To: Perl Beginners
> Subject: Re: perl mysql question
> 
> --As of Monday, April 26, 2004 5:30 PM -0700, Christopher Lyon is
alleged
> to have said:
> 
> > So, how to I get the values to look like in variable so that I can
push
> > them back into a new table:
> >
> > New Table
> > name                count
> > ---------+-------
> > Widgets-A|  25
> > Widgets-B|  10
> > Widgets-C|  20
> > Widgets-D|  10
> > Widgets-E|  25
> >
> > Any ideas?
> 
> --As for the rest, it is mine.
> 
> Sure: create a hash, using field one as the key, and *add* (not
insert)
> the
> count to the value of each element of the hash.  Then store the hash
in
> the
> database.
So, I have this:

select * from table;
widget-a -> 10
widget-b -> 10
widget-c -> 10
widget-a -> 20
widget-b -> 20

I run this:
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.






--
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