0

我知道这是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 不是非常熟悉,但任何帮助将不胜感激!

4

1 回答 1

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};
于 2013-12-31T17:40:00.510 回答