Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with hashes 2

Status
Not open for further replies.

MJAZ

Programmer
Aug 1, 2006
73
US
Hello! I am trying to use a CGI script that uses a URL to run a function and display pages. Like this:

Code:
our %funcToAction = ('email_verify' => everify(),
                    'account_deactivate' => deactivateAccount(),
                    'edit_settings' => accountEditSettings() );

What I want it to do is when it gets supplied a URL, lets say
Code:
myscript?action=email_verify
, it takes the value of action and runs the function associated with it. Thanks in advance for your help, I'm pretty new to Perl.

Matt
 
how are you currently getting your URI data in variables?

Code:
myscript?action=email_verify

are you using the CGI module to parse the data? Something like:

Code:
use CGI qw/:standard/;
my $email_verify = param('action')

or something different?



- Kevin, perl coder unexceptional!
 
What you need to use is a dispatch table.
Code:
#!/usr/bin/perl

use strict;
use CGI;
my $q = new CGI;

my $dispatch = {
    email_verify        => \&everify,
    account_deactivate  => \&deactivateAccount,
    edit_settings       => \&accountEditSettings,
};

my $action = $q->param('action');

$dispatch->{$action}->() or die "Action not found!";

sub everify {
    print "Verify";
}

sub deactivateAccount {
    print "Deactivate";
}

sub accountEditSettings {
    print "Edit";
}

M. Brooks
 
yea, thats pretty much what I would suggest too.

- Kevin, perl coder unexceptional!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top