在使用"strict refs"时,不能使用字符串("1")作为子程序ref

sny*_*rxc 0 perl dispatch-table

我知道这是一个副本不能使用字符串("1")作为子程序ref,而"严格参考"在使用, 但我无法弄清楚我的问题是调用分派表.代码似乎执行,但日志中出现以下错误: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
Run Code Online (Sandbox Code Playgroud)

我不确定它是否与我使用自定义模块这一事实有关,而且它可能是愚蠢的,因为我对Perl并不是非常熟悉,但任何帮助都会受到赞赏!

Сух*_*й27 5

($dispatch_table->{$perl_function}->(\@ARGV) || sub {})->();
Run Code Online (Sandbox Code Playgroud)

是一回事

my $x = $dispatch_table->{$perl_function}->(\@ARGV);
($x || sub {})->(); # $x is probably not code ref
Run Code Online (Sandbox Code Playgroud)

尝试,

($dispatch_table->{$perl_function} || sub {})->(\@ARGV);
Run Code Online (Sandbox Code Playgroud)

也许

$_ and $_->(\@ARGV) for $dispatch_table->{$perl_function};
Run Code Online (Sandbox Code Playgroud)