Here's the relevant snippet having errors:
my %Pages = (
'Login' => \&validateAccount,
'Create Account' => \&createAccount,
'User Options' => \&userOptions,
'View Flashcards' => \&displayCards,
);
if ( !$q->param ) {
loginPage();
}
elsif ($q->param('action')) {
my $page = $q->param('action');
$Pages{$page}->();
}
else {
noSuchPage();
}
When PerlJam sends an action parameter with the 'displayCards' value, he gets uninitialized value errors in the $Pages{$page} call.
My solution would be to say:
my $action = $query->param('action');
if (exists $Pages{$action}) {
$Pages{$action}->();
} else {
noSuchPage();
}
This would reveal that there's no key in %Pages named 'displayCards'. Instead, it's 'View Flashcards'. :) |