Perl throws “keys on reference is experimental”

ε祈祈猫儿з 提交于 2019-12-22 04:46:08

问题


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)

Here is the problem

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

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

line 94 of the module shows

my $num_regexes = scalar keys $token_regexes;

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";
});

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?


回答1:


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

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) { ... }

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.

Specifically, change

my $num_regexes = scalar keys $token_regexes;

to

my $num_regexes = scalar keys %$token_regexes;


来源:https://stackoverflow.com/questions/29613951/perl-throws-keys-on-reference-is-experimental

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!