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