in reply to Logical/defined or as lvalue

What is the reason for the logical/defined or operators not to provide an lvalue as result?

I don't know. It may have been oversight, or there may have been an explicit or implicit rationale that has most likely been lost in the mists of time.

Would changing this behaviour break any existing code?

My first guess would be autovivification: $h{$_} behaves differently in lvalue and rvalue contexts, which is already enough to cause regular confusion. Also any classes that provide overloading of these operators is likely to have been designed to the current behaviour.

Is the usage of ${\(X // Y)} as an lvalue well-defined behaviour?

I think it probably depends on X and Y, but in the cases where it is legal to take the reference, I think I'd expect the dereference to be well-behaved. In other words: where it works, I wouldn't expect it to suddenly stop working.

Replies are listed 'Best First'.
Re^2: Logical/defined or as lvalue
by Fletch (Bishop) on Sep 04, 2024 at 03:09 UTC

    I almost hazarded a similar guess with similar rationale (having to account for an undef result being the destination target for autovivification). My gut reaction to concept is that it's something that I'd likely at least "ding" were I to see it in a code review (conceivably it's similar but shorter for doing an assignment to different places in different legs of an if/else maybe but feels like tending towards obfuscation . . . meh).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re^2: Logical/defined or as lvalue
by jo37 (Curate) on Sep 04, 2024 at 08:40 UTC
    My first guess would be autovivification: $h{$_} behaves differently in lvalue and rvalue contexts,...

    True, but currently the usage of X // Y as an lvalue results in a compile error. I'm not sure if this is any different in overloading.

    Update:
    One overlooked detail:

    Also any classes that provide overloading of these operators...

    Logical operators cannot be overloaded.

    Greetings,
    🐻

    $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$
Re^2: Logical/defined or as lvalue
by LanX (Saint) on Sep 03, 2024 at 22:15 UTC
    Hi hv's ghost writer, :)

    > My first guess would be autovivification: $h{$_} behaves differently in lvalue and rvalue contexts, which is already enough to cause regular confusion.

    Do you have an example?

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

Re^2: Logical/defined or as lvalue
by hv (Prior) on Sep 03, 2024 at 21:56 UTC

    That's strange, I was definitely logged in when I wrote that, and I'm still logged in (as hv).

      For future reference, you can just send a /msg to gods and they can change the ownership of the node to yourself.