in reply to Re: Strange memory growth
in thread Strange memory growth

So are you saying that Huck's post should have used exists, instead of defined? To be absolutely clear, can you post a quick example similar to Huck's? Auto-vivification is obviously the root cause problem here ... but are you saying that defined will auto-viv too? (That does seem counter-intuitive, but ...)

Replies are listed 'Best First'.
Re^3: Strange memory growth
by Anonymous Monk on Feb 15, 2018 at 14:13 UTC

    No difference between exists and defined in this regard. In both cases, the *intermediate* levels will spring into existance. The last level isn't dereferenced as a hash.

    If you have perl installed, you can try it out yourself:

    $ perl -e 'use Data::Dump; exists $a->{foo}{bar}; dd $a;' { foo => {} } $ perl -e 'use Data::Dump; defined $a->{foo}{bar}; dd $a;' { foo => {} }

      I guess that I'm still confused. When I look at Huck's solution, I see that short-circuit conditional expression optimization will stop the evaluation at the first "false" result. Therefore, as far as I can see, no auto-vivification would occur. My question was therefore whether it actually mattered which function-call Huck used.
        Yes that is true, the function used does not matter. The solution from huck is fine. I updated my original post with a similar example.