使用中不能使用字符串 ( "1" ) 作为子例程引用"strict refs"



我知道这是 不能使用字符串 ("1") 作为子例程引用的副本,而使用"严格引用"但是我无法弄清楚调用调度表的问题是什么。代码似乎已执行,但日志中出现以下错误:Can't use string ("1") as a subroutine ref while "strict refs" in use at C:/filepath/file.pl line 15.

#! C:strawberryperlbinperl
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 不是很熟悉,但任何帮助将不胜感激!

($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};

最新更新