As Brian mentioned: it still does it, it just warns you. Warnings tell you about certain manipulations with effects you might not have intended.
You are specifically asking for the value of $histogram{$_}
, adding 1 to it and then assigning it to the same slot. It's the same way that I wouldn't expect autovivification to work here:
my $hash_ref = $hash_for{$key_level_1};
$hash_ref->{$key_level_2} = $value;
as it does here:
$hash_for{$key_level_1}{$key_level_2} = $value;
Magic probably does not work like optimization. And optimizing compiler would notice that a = a + 1
is the same thing as a++
so that were there an increment operator in the assembly language, it could use that optimized instruction instead of pretending that it needed to preserve the first value, and then overwriting it because it isn't actually needed.
Optimization is extra scrutiny and overhead once for improved performance every run. But there is no guarantee in a dynamic language that you aren't adding overhead at the same rate you would otherwise be trying to reduce it.