简体   繁体   中英

how to solve the “Experimental values on scalar is now forbidden” problem in perl

In Perl 5.26.2 I get:

Experimental each on scalar is now forbidden at a.plx line 67.
Type of arg 1 to each must be hash or array (not private variable) at a.plx   
line 67, near "$val)"
Execution of a.plx aborted due to compilation errors.

Where line 67 is the while in

 67 while (my ($ip, $val2) = each($val))
 68 {
       ......
    }

each takes a hash, not a reference. [1] Therefore,

while (my ($ip, $val2) = each($val))

should be

while (my ($ip, $val2) = each(%$val))

  1. Perl 5.12, 5.14 and 5.16 allowed a reference to be used. This was a mistake.

    Perl 5.18, 5.20 and 5.22 still allowed it, but warned if you did.

    Perl 5.24 reverted this addition.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM