in reply to Making hashes from arrays

Untested and broken (see Abigail-IIs post below), but I think your while loop could be replaced by

1 while @hall_details{$hall_id}{ qw[ hall_id hall_name upload_date uploaded_by photo_id ] } = $sth->fetchrow_array();

Update: I should never post untested code. It always bites me. Again, I think this would work.

my @fields; @( hall_details{$hall_id} }{ qw[ hall_id hall_name upload_date uploaded_by photo_id ] } = @fields while @fields = $sth->fetchrow_array();

which would save a lot of typing and to the offense of the "it don't matter how long it takes brigade", it might even be slightly more efficient:) Feel free to reformat that however suits your view of beauty.

That said, I have a sneaky suspicion that you can ask DBI to return the data as a hash to begin with, which would undoubtably be your best option.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

Replies are listed 'Best First'.
Re: Making hashes from arrays
by Abigail-II (Bishop) on May 22, 2003 at 23:21 UTC
    That doesn't look right, even after fixing the syntax error. Since you call $sth -> fetchrow_array () until it returns an empty list, the last assignment will be the equivalent of:
    @{$hall_details {$hall_id}} {qw [ ... ]} = ();

    Effectively wiping out the content the OP was interested in.

    Abigail