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


In reply to Making hashes from arrays by CodeJunkie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.