Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Logical/defined or as lvalue

by LanX (Saint)
on Sep 03, 2024 at 19:57 UTC ( [id://11161549]=note: print w/replies, xml ) Need Help??


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$

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2026-03-05 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.