I have a problem with a Perl script but don't know why. I have something like this
..
$ref = pfget($Pf, "criteria");
%criteria= %$ref;
..
..
foreach $key (keys %criteria) {
$expr = %criteria->{$key};
..
}
The line $expr = %criteria->{$key} gives me an error
Using a hash as a reference is deprecated
I've tried $expr = $criteria{$key} but the script is not working as it should be.
Have you got any idea where I am going wrong?
%criteria in scalar context is suppose to return statistics about the hash.
$ perl -E'my %h = ( a=>1, b=>2, c=>3 ); say scalar %h'
3/8
So
%criteria->{$key}
means
"3/8"->{$key}
But a bug in Perl causes it to behave as
(\%criteria)->{$key}
The warning is telling you that your code is buggy because your code is relying on a bug in Perl. Use
$criteria{$key}
or avoid the wastefulness of creating %criteria and use
for my $key (keys %$ref) {
... $ref->{$key} ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With