CodeJunkie has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I have the following sub routine and I want to make it more efficient, or at least less lines of code. I'm sure there must be a better way of achieving the same effect with some clever perl 'one liner'!!!!
Ok, here's my code.
sub getHallDetails() { my ($hall_id,$dbh)=@_; my $sth=$dbh->prepare("select hall_name,upload_date,uploaded_by,phot +o_id from hall_details where hall_id='$hall_id' limit 1;"); $sth->execute(); my %hall_details=(); while (my ($hall_name,$upload_date,$uploaded_by,$photo_id) = $sth->f +etchrow_array()) { $hall_details{$hall_id}{hall_id}=$hall_id; $hall_details{$hall_id}{hall_name}=$hall_name; $hall_details{$hall_id}{upload_date}=$upload_date; $hall_details{$hall_id}{uploaded_by}=$uploaded_by; $hall_details{$hall_id}{photo_id}=$photo_id; } return %hall_details; }
It's not great I realise this, how can I reduce the number of lines I am typing here?
Thanks, your advice is greatly appreciated,
Tom
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Making hashes from arrays
by theorbtwo (Prior) on May 22, 2003 at 23:08 UTC | |
|
Re: Making hashes from arrays
by Zaxo (Archbishop) on May 23, 2003 at 00:09 UTC | |
by adamk (Chaplain) on May 23, 2003 at 00:20 UTC | |
|
Re: Making hashes from arrays
by BrowserUk (Patriarch) on May 22, 2003 at 23:15 UTC | |
by Abigail-II (Bishop) on May 22, 2003 at 23:21 UTC | |
|
Re: Making hashes from arrays
by nite_man (Deacon) on May 23, 2003 at 07:10 UTC | |
|
Re: Making hashes from arrays
by wufnik (Friar) on May 23, 2003 at 07:56 UTC |