Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Calling different methods based on a CGI parameter

by moritz (Cardinal)
on May 21, 2008 at 12:46 UTC ( #687760=note: print w/replies, xml ) Need Help??


in reply to Calling different methods based on a CGI parameter

Although dispatch tables are the prefered way to do it, you can use variables as sub names:
#!/usr/bin/perl use strict; use warnings; sub sa { print "sub sa\n"; } sub sb { print "sub sb\n"; } my $name = 'a'; # using the symbol table $main::{'s' . $name}->(); $name = 'b'; # using symbolic references: no strict 'refs'; &{"s$name"}();

Be aware that this might open some security holes depending on your application. You have been warned!

Replies are listed 'Best First'.
Re^2: Calling different methods based on a CGI parameter
by ysth (Canon) on May 21, 2008 at 18:11 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://687760]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (1)
As of 2023-09-27 23:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?