in reply to Logical/defined or as lvalue

I wasted too much time on this ;)

Anyway, my best suggestion, please don't use this deref-ref syntax for the sake of readability

Try something like the following ors or defs and you are free to chain even more than two operators and assign too.

sub ors :lvalue { $_ && return $_ for @_ ; return $_[-1]; } # define analogous &defs ors($x,$y,$z) = 42;

This could also be included in a module like List::Util (if really missing, compare any and all

Regarding documentation: the perlop Doc for // also covers || and &&.

They talk at length about returning the scalar value of the first operand because of the Boolean test, this might be related.

FWIW, I was also experimenting with

sub lv(&) :lvalue { ${ \( $_[0]->() ) } } lv{ $a // $b } = 666;

But this doesn't work because I can't specify that the prototype & code-block is an lvalue too. ( Probably a posteriori???)

Finally I discovered what looks like a bug at least in 5.36 inside the debugger.

feature 'signatures' seems to be enabled by default when testing sub declarations inside a prompt of perl -de0

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

¹) I'm having a deja-vu right now, did we discuss this before?

Replies are listed 'Best First'.
Re^2: Logical/defined or as lvalue
by jo37 (Curate) on Sep 04, 2024 at 16:50 UTC

    It wasn't Perl if there were no other way to do it.

    Maybe my questions were misleading: I'm not searching for a solution to a specific problem. I'm asking if a feature was desirable and feasible.

    Greetings,
    🐻

    $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$