I've got an odd situation here, where I'm not sure if mod_perl is coming into play or not (as it's compiled into my httpd, but not configured in httpd.conf). Please bear with me as I explain the complexities.
I've got a script that's fetching quiz questions and answers out of a database and displaying them to the browser; said script later checks the user's answer and gives them a reply.
Since I figured I'd be talking to the database a lot, I made my database handle a global variable (or at least I think I did; I'm using strict, and I declared it as "my $dbh = DBI->connect..." outside of any subroutine or block). I've been able to use it with no problems throughout the script, including on different calls to the script (i.e. on the category display page of the quiz, the question display page, and the answer page).
I also decided to make the reference generated by fetchrow_hashref() when I got each question global (by the same method), since I figured I'd be using it in many subroutines, through different requests.
When I first dereferenced objects out of the hash, everything worked great:
sub display_questions()
{
my $template = HTML::Template->new(
filename => '/home/www/elderlinda/quiz-template.tmpl',
die_on_bad_params => 0);
$template->param(question => $qref->{question},
ans_a => $qref->{ans_a},
ans_b => $qref->{ans_b},
ans_c => $qref->{ans_c},
category => param("category"),
number => $qref->{number}
);
print $template->output;
}
This displayed the page with the question and possible answers nicely. Note that I did not ever call the same key twice out of the hash.
When I attempted to dereference a key for the second time out of the hash, I got an empty value:
sub check_answer()
{
my $subans = param("ANS");
my $qnum = $qref->{number};
...
}
Would this be because hash references are transient? Or would it be because dereferencing a key twice makes a second call to fetchrow_hashref()? Any ideas how I would fix this?
Thanks,
Alex Kirk