swandown has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
please forgive if this is a very newbie question. I have course data returned from DB by something like:
$sql = qq{select course_id,course_name,course_sitting_id,course_sittin +g_date from courses}; $sth = $dbh->prepare($sql) or die . . .; $sth->execute() or die . . . .; while (@fetch = $sth->fetchrow) { . . . .
Which returns data like :
10,Programming 101,1,01-SEP-2011 20,Databases 101,1,03-SEP-2011 10,Programming 101,2,20-SEP-2011 20,Databases 101,2,27-SEP-2011
I need to get it into the following hash of hashes structure :
my %courses= ( '10' => { 'desc' => 'Programming 101', 'sittings' => { '1' => '01-SEP-2011', '2' => '20-SEP-2011', }, }, '20' => { 'desc' => 'Databases 101', 'sittings' => { '1' => '03-SEP-2011', '2' => '27-SEP-2011', }, }, );
But I'm completely stumped . . wish I could show what code I got . . . but I got nothing . . . . Many Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hash of Hashes
by toolic (Bishop) on Aug 30, 2011 at 12:27 UTC | |
by swandown (Novice) on Aug 30, 2011 at 13:34 UTC | |
|
Re: Hash of Hashes
by Corion (Patriarch) on Aug 30, 2011 at 12:22 UTC | |
|
Re: Hash of Hashes
by Neighbour (Friar) on Aug 30, 2011 at 14:18 UTC |