vishi has asked for the wisdom of the Perl Monks concerning the following question:
Hi Gurus!
Here's what I'm trying to do : I have a database table that has rows for bugs against a few components in the system like so
COMP BUGNO ------ ----- USRINT 1111 HWARE 1232 USRINT 1021 KERNEL 4384 DRIVER 4894 KERNEL 4398 USRINT 1233
Now, I want to convert this data into a Perl Hash where in the "key" is the faulty component and the "value" is a list of bugs against that faulty component.
Now I have used DBI to get the values and write them to a hash like so
our $stmt = qq/select component, bug_no from request where status like + 'OPEN'/; our $sth = $dbh->prepare($stmt); $sth->execute() or die DBI->errstr; my %hash; while( my( $comp, $bug_num ) = $sth->fetchrow_array() ) { $hash{ $comp } = $bug_num; }
What's happening here is that data is being overwritten when a new bug comes against an existing component. I want this bug to be appended to the end of that list so that one print of this hash gives me a list of components and bugs that are open against that component like so:
USRINT 1111, 1021, 1233 HWARE 1232 KERNEL 4384, 4398 DRIVER 4894
I'm not able to get this done. Any help is appreciated!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Database Rows into Perl Hash
by vishi (Beadle) on Mar 07, 2015 at 12:31 UTC | |
by Athanasius (Archbishop) on Mar 07, 2015 at 12:37 UTC | |
by choroba (Cardinal) on Mar 07, 2015 at 12:42 UTC | |
by duelafn (Parson) on Mar 07, 2015 at 12:43 UTC |