in reply to No autovivification, for loop aliasing, lvalue vs rvalue in for loops

>
# "Can't use an undefined value as an ARRAY reference": # @{$$n{'x'}} and die; print "\n\nnow the same but in loop:\n"; for my $e (@{$$n{'x'}}) { } print "why 'x' autovivified?\n"; print Dumper $n;

Well you get right the same effect without disabling autovivification.

While it feels like autovivification there's IMHO technically an aliasing/for-loop magic happening. This is probably not covered by the internal autovivification mechanisms (i.e. explicitely accessing sub-elements) and hence was forgotten.

Not sure if it's easy to implement, but you should commit a bug report to raise the question.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

  • Comment on Re: No autovivification, for loop aliasing, lvalue vs rvalue in for loops
  • Download Code

Replies are listed 'Best First'.
Re^2: No autovivification, for loop aliasing, lvalue vs rvalue in for loops
by leszekdubiel (Scribe) on Sep 02, 2016 at 20:36 UTC
    Ok -- I will file a bug on that. Thank you.
      Why I stop autovivification... I am processing information about manufacturing mirrors in our company (dubielvitrum.pl), and two hashes are compared and during that comparison they are modified. I don't want hash to be modified when I just look for values in it. Another reason is I want to have warnings when I try to write on deep levels on such hashes, because this means error quite often.

        I don't want hash to be modified when I just look for values in it. Another reason is I want to have warnings when I try to write on deep levels on such hashes, because this means error quite often.

        :) You don't need autovivification.pm module for that, see Data::Diver