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?


In reply to Re: Logical/defined or as lvalue by LanX
in thread Logical/defined or as lvalue by jo37

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.