http://www.perlmonks.org?node_id=260274

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