Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by LanX (Cardinal)
on Dec 20, 2019 at 22:57 UTC ( #11110461=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11110461]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2020-11-25 06:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?