in reply to variable function thingy
Btw, if the $action variable comes from user input - most likely in a CGI script -, you will want to check that it actually contains the name of a function you have intended for public calling. That's easiest to make sure if you use a hash to map names to coderefs.
Alternatively, you could put the public functions in a package and use the symbol table hash to get at them.
if(exists $Action::{$action}) { $Action::{$action}->(@params); } else { croak "No such action '$action'"; } package Action; sub post { # ... }
Makeshifts last the longest.
|
|---|