in reply to Re^4: How to call subroutines using variables ?
in thread How to call subroutines using variables ?

You're not using strict, are you? That ought to call those subroutines immediately and take a reference to their results.

  • Comment on Re^5: How to call subroutines using variables ?

Replies are listed 'Best First'.
Re^6: How to call subroutines using variables ?
by bradcathey (Prior) on Jun 10, 2007 at 12:25 UTC

    Obviously I'm missing something key here. I have:

    my @val = (\val_input,\val_input,\val_input,\val_input,\val_number,\v +al_date,\val_number,\val_filter); for my $i ( 0 .. $#list) { $code = $val[$i]; #which subroutine to call? ($sql{ $list[$i] }, $error) = $self->$code( $mand[$i], $self->query +->param($list[$i] )); if ( $error-> { msg } ) { push @errors, ucfirst($list[$i])." $error +->{ msg }" } }

    Sounds like I need a no strict 'refs' block in there. Possibly:

    } no strict 'refs'; $code = $val[$i]; }

    But now I'm just speculating.


    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot

      Why would you need to disable strict for this block:

      { no strict 'refs'; $code = $val[$i]; }

      Without seeing the rest of the code, I can't tell you exactly what this does:

      my @val  = (\val_input,\val_input,\val_input,\val_input,\val_number,\val_date,\val_number,\val_filter);

      I can tell you that it doesn't take references to val_input, val_number, and so on. If you've predeclared those subroutines, Perl will call them and then take references to their return values. Otherwise, they're bare words, and strict will complain.