Bootstrap FreeKB - Perl (Scripting) - Resolve "Experimental keys on scalar is now forbidden"
Perl (Scripting) - Resolve "Experimental keys on scalar is now forbidden"

Updated:   |  Perl (Scripting) articles

Let's say something like this is being returned.

Experimental keys on scalar is now forbidden at /path/to/example.pl line 10.
Type of arg 1 to keys must be hash or array (not private variable) at /path/to/example.pl line 10, near "$food) "
Execution of /path/to/example.pl aborted due to compilation errors.

 

I got this when attempting to loop over a variable hash that contained key/value pairs. In this example, the variable named $food is a hash containing key/value pairs.

foreach my $key (keys $food) {
  print "$key\n";
}

 

For example, my $food variable contains a hash of key/value pairs like this.

$VAR1 = {
          'fruit' => 'apple',
          'veggy' => 'pepper'
        };

 

I resolved this by updating my for each loop to have %{$food}

foreach my $key (keys %{$food}) {
  print "$key\n";
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 6cd0a7 in the box below so that we can be sure you are a human.