in reply to CGI.pm and frames

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'. :)

Replies are listed 'Best First'.
Re: Re: CGI.pm and frames
by PerlJam (Sexton) on Feb 23, 2001 at 12:55 UTC
    Thank you so much kind sir. I can't believe I didn't notice that :)
    ----
    Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated failures. Persistence and determination alone are omnipotent. --Calvin Coolidge (1872-1933)