in reply to Re^3: unexpected modify hash in a distance with grep { $_ } (inconsistent behaviour of aliasing)
in thread unexpected modify hash in a distance with grep { $_ }

> Personally I don't like like this behaviour much, but it was added in 5.004, before my time as a p5 porter

Which of both?

I personally find the behaviour of the sub arg aliasing far less surprising.

The other behaviour rather looks like sacrificing logic for performance or easier code logic.

I suppose changing that might be too expensive now, but most code doesn't try to assign to $_ in a loop.

If we are going to keep this behaviour, we'll need to document it properly.

Something like loop aliasing always triggers autovivification

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

  • Comment on Re^4: unexpected modify hash in a distance with grep { $_ } (inconsistent behaviour of aliasing)

Replies are listed 'Best First'.
Re^5: unexpected modify hash in a distance with grep { $_ } (inconsistent behaviour of aliasing)
by dave_the_m (Monsignor) on Dec 21, 2019 at 00:01 UTC
    To clarify:

    I am happy with the fact that 'for', 'grep' etc evaluate their args in lvalue context and thus autovivify, and I don't wish it to change. I find that this behaviour makes the rules for autovivification logically simple(r) and consistent.

    I am unhappy with the deferring mechanism in hash lookups when used as an arg to a function call. It's a tricksy special-case behaviour and is hard to explain (above, I had to start talking about PVLVs and showing the output of Devel::Peek). It adds performance + memory overhead for such function calls, and is too clever for its own good. But I'm not proposing that it be be changed, since it was intentional behaviour added over 20 years ago.

    Dave.

      > I find that this behaviour makes the rules for autovivification logically simple(r) and consistent.

      Maybe... But if it was that easy why can't we find it documented in the perldocs.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice