Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl throws "keys on reference is experimental"

Tags:

cgi

perl

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?

like image 497
kristian nissen Avatar asked Apr 13 '15 19:04

kristian nissen


1 Answers

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;
like image 83
Hunter McMillen Avatar answered Sep 24 '22 18:09

Hunter McMillen