Slightly better to use a hash of coderefs:
%func = ( one => sub { print "Sub one says: $_[0]" }, two => sub { print "Sub two says: $_[0]" }, three => sub { print "Sub three says: $_[0]" }, four => sub { print "Sub four says: $_[0]" }, ); my $sub = CGI::param('type'); my $data = CGI::param('info'); if ( exists $func{$sub} ) { $func{$sub}->($data) } else { $func{one}->($data) }
--Bob Niederman, http://bob-n.com
All code given here is UNTESTED unless otherwise stated.
In reply to Re: Avoiding user-input in sub calls.
by bobn
in thread Avoiding user-input in sub calls.
by pekkhum
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |