$incl has to contain a reference to a function (e.g. $incl = \&my_func), or the name of a function if strict 'subs' is off (e.g. $incl = 'my_func'). In your case, it contains much more than that. It contains a bit of (uncompiled) Perl code.
You have two options.
You can use eval EXPR to execute the Perl code. That's rather slow, and it can be vulnerable to injection attacks.
push(@incl,"&CreateLogInForm(\$page,\$error)"); foreach $incl (@incl) { $page .= eval $incl; }
You can wrap the function call (your Perl code) with an argument-less subroutine. This method doesn't suffer from the problem listed above.
push(@incl, sub { &CreateLogInForm($page,$error) }); foreach $incl (@incl) { $page .= &$incl; }
There are subtle differences in the meaning of $page and $error between the two:
{ my $page = 'abc'; my $error = 'def'; push(@incl,"&CreateLogInForm(\$page,\$error)"); $page = 'ghi'; $error = 'jkl'; } foreach $incl (@incl) { my $page = 'mno'; my $error = 'pqr'; $page .= eval $incl; # Uses 'mno' and 'pqr' }
{ my $page = 'abc'; my $error = 'def'; push(@incl, sub { &CreateLogInForm($page,$error) }); $page = 'ghi'; $error = 'jkl'; } foreach $incl (@incl) { my $page = 'mno'; my $error = 'pqr'; $page .= &$incl; # Uses 'ghi' and 'jkl' }
In reply to Re: How do I execute an array element?
by ikegami
in thread How do I execute an array element?
by hesco
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |