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
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.