Perl 抛出 "keys on reference is experimental"

Perl throws "keys on reference is experimental"

开发环境为OSX 10.10.3,Perl -v

This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-thread-multi-2level
(with 2 registered patches, see perl -V for more detail)

问题来了

我将项目从我的本地环境移动到 Windows 服务器,现在我收到以下错误:

"keys on reference is experimental at CGI/Router.pm line 94."

模块的第 94 行显示

my $num_regexes = scalar keys $token_regexes;

整个模块可以在这里找到https://github.com/kristiannissen/CGIRouter

我像这样实例化路由器模块

$router->add_route( 'GET', '/home', sub {
 print header( -type => 'text/html', -charset => 'utf-8' );

 print "Hello Pussy";
});

我在本地没有这个问题,但现在我要转移到生产服务器上,我遇到了这个问题。据我所知,它与特定的 Perl 版本有关,但在我要求提供商升级 Perl 之前,我想知道是否有什么办法可以避免这个问题?

键的文档 perldoc keys 关于在哈希引用上使用键是这样说的:

Starting with Perl 5.14, keys can take a scalar EXPR, which must contain a reference to an unblessed hash or array. The argument will be dereferenced automatically. This aspect of keys is considered highly experimental. The exact behaviour may change in a future version of Perl.

for (keys $hashref) { ... }

要避免此问题,升级 Perl 将无济于事。该模块需要更新以按预期方式使用密钥,而不是使用实验性功能。也就是说,它需要在调用 keys.

之前取消引用 hashref

具体来说,改变

my $num_regexes = scalar keys $token_regexes;

my $num_regexes = scalar keys %$token_regexes;