SPUG: Subroutine references with "strict refs"

Dan Ebert dan at enic.cc
Fri Oct 13 16:39:43 CDT 2000


Hello.  I have a question for the group ...

I am working a bit of code for a CGI script whose behavior is largely 
controlled by a hidden field "action" on the form being submitted.

I am attempting to call a subroutine with the same name as the "action" 
parameter.  Here is the snip of code:


     my $action = $in{action}; # $in{action} holds the value of the 
"action" parameter from the form.

     eval{ &$action; }; # error trap
     if ( ! $@ ){
         &$action;
     }
         else {
            # do something with the error
         }

This code works perfectly if I don't use strict; at the beginning of my 
code, but if I use strict; I get this error:

Error: Can't use string ("remove") as a subroutine ref while "strict refs" 
in use at ....


Any ideas?  The only other way I come up with is using a "Dispatch table" 
hash of parameter->references-to-subroutines (as described on p 54 of 
O'Reilly's Advanced Perl Programing), but I'd rather not do that if possible.

Thanks!
--------------------------------------------------
The nice thing about standards is that there are
    so many of them to choose from.
         - Andrew S. Tanenbaum

Dan Ebert   <dan at enic.cc>
eNIC Corporation, www.enic.cc
--------------------------------------------------


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/archives/spug-list/attachments/20001013/10b14039/attachment.htm


More information about the spug-list mailing list