Perl throws “keys on reference is experimental”

吃可爱长大的小学妹 提交于 2019-12-05 05:48:25
Hunter McMillen

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