Perl抛出“参考键是实验性的”提示。 [英] Perl throws "keys on reference is experimental"

查看:83
本文介绍了Perl抛出“参考键是实验性的”提示。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开发环境为OS X 10.10.3,Perl -v

Development environment is OS X 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 Server,现在我收到以下错误:

I moved the project from my local environment to a Windows Server and now I get the following error:

参考键在CGI / Router.pm第94行处是实验性的。

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

模块的第94行显示

my $num_regexes = scalar keys $token_regexes;

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

the entire module can be found here https://github.com/kristiannissen/CGIRouter

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

I instantiate the router module like this

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

 print "Hello Pussy";
});

我在本地没有这个问题,但是现在我转到生产服务器,我得到了这个问题。据我所知,它与特定的Perl版本有关,但是在我要求提供商升级Perl之前,我想知道我能做些什么来避免这个问题?

I don't have this issue locally, but now that I am moving to production server, I get this issue. From what I can tell, it's related to a specific Perl version, but before I ask the provider to upgrade Perl, I would like if there is anything I can do to avoid this issue?

推荐答案

密钥文档, perldoc键 ,关于在散列引用上使用键的说法是这样的:

The documentation for keys, perldoc keys, has this to say about using keys on a hash reference:


从Perl 5.14开始,键可以采用标量EXPR,该标量必须包含对未加祝福的哈希或数组的引用。该参数将自动取消引用。键的这一方面被认为是高度实验性的。确切的行为可能会在Perl的将来版本中改变。

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将无济于事。需要更新模块以按预期方式使用键,而不是使用实验性功能。也就是说,它需要在调用之前取消对hashref的引用。

To avoid the issue, upgrading Perl won't help. The module needs to be updated to use keys in the expected manner instead of using an experimental feature. That is, it needs to dereference the hashref before calling keys.

具体地说,更改

my $num_regexes = scalar keys $token_regexes;

my $num_regexes = scalar keys %$token_regexes;

这篇关于Perl抛出“参考键是实验性的”提示。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆