Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Calling different methods based on a CGI parameter

by moritz (Cardinal)
on May 21, 2008 at 12:46 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-20 03:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found