我知道这是Can't use string ("1") as a subroutine ref while "strict refs" in use的副本
但我无法弄清楚调用表的问题是什么。代码似乎已执行,但日志中出现以下错误:Can't use string ("1") as a subroutine ref while "strict refs" in use at C:/filepath/file.pl line 15.
#! C:\strawberry\perl\bin\perl
use strict;
use warnings;
use Custom::MyModule;
use CGI ':standard';
my $dispatch_table = {
getLRFiles => \&Custom::MyModule::getLRFiles,
imageMod => \&Custom::MyModule::imageMod,
# More functions
};
my $perl_function = param("perl_function");
($dispatch_table->{$perl_function}->(\@ARGV) || sub {})->(); # Error occurs on this line
我不确定它是否与我使用自定义模块这一事实有关,而且它可能是愚蠢的,因为我对Perl并不是非常熟悉,但任何帮助都会受到赞赏!< / p>
答案 0 :(得分:5)
($dispatch_table->{$perl_function}->(\@ARGV) || sub {})->();
与
相同my $x = $dispatch_table->{$perl_function}->(\@ARGV);
($x || sub {})->(); # $x is probably not code ref
尝试,
($dispatch_table->{$perl_function} || sub {})->(\@ARGV);
或者
$_ and $_->(\@ARGV) for $dispatch_table->{$perl_function};