Sara wrote:
> use strict;
> use warnings;
> use CGI;
> 
> my $q = new CGI;
> 
> my $do = $q->param('do') || 'main'';
> 
> if ($do) {
> &$do;
> }
> 
> sub main {
> blah blah
> }
> =========================================
> Trying to call the subroutine main from variable $do but I am gettin' error:
> Can't use string ("main") as a subroutine ref while "strict refs.
> But somehow I don't want to remove the 'use Strict;'
> 
> Any way out?

my $q = new CGI;

my $do = $q->param( 'do' ) || \&main;

if ( ref $do eq 'CODE' ) {
    $do->();
}

sub main {
    blah blah
}



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to