in reply to Array of Hashes Issue

If you're not sure what a data structure looks like, you can use modules like Data::Dumper or Data::Dump::Streamer (see How can I visualize my complex data structure? for examples). If you're not sure how to navigate through it, perldsc has some good information. perlref and perlreftut may also help if you are not familiar with references.

That said, it looks like you've got a few problems in your code. When simplified, it looks like this:

my @questions; my %pending; while($sth->fetch) { while($sth->fetch) { if($pending{is_correct}) { $pending{correct_answer} = $pending{answer}; } else { ## Add to array of wrong answers push @{$pending{wrong}}, $pending{answer}; } } push @questions, %pending; } return @questions;
First, it looks like you're overwriting $pending{correct_answer} each time, and all of the wrong answers are ending up in the same array (@{$pending{wrong}}). If I can read your intent correctly, I think you need something like $pending{$id}{correct_answer} and @{$pending{$id}{wrong}}.

Second, you flatten the %pending hash when you push it onto @questions. If you really want to use an array (see below), try pushing a hash reference instead: push( @questions, \%pending ) (note that this would require you to tighten the scope of %pending).

Third, you are returning an array, but an array reference might be better: return \@questions;

Finally, I think you might want to reconsider the type of data structure that you are creating and returning. Something like the following might work:

%hash = ( $question_id => { correct_answer => $whatever, wrong_answers => [ $oops, $my_bad, ... ] },
A complex data structure like this should be returned as a reference: \%hash.

Update 1: Wow, am I slow tonight.

Update 2: As we discussed in the cb, 1) you may also want to consider using a join and combining your queries into a single SQL statement and 2) the DBI fetchall_*ref methods may help you simplify the code.

HTH