Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: can sub check context for lvalue vs rvalue context?

by LanX (Saint)
on May 09, 2018 at 07:06 UTC ( [id://1214257]=note: print w/replies, xml ) Need Help??


in reply to Re^2: can sub check context for lvalue vs rvalue context?
in thread can sub check context for lvalue vs rvalue context?

> Yeah, returning a tied value is what I was grudgingly working on, as I didn't think it would be very efficient

There is probably a solution without XS ...

You could compare the caller in the tied STORE and set a flag $islvalue for the next call.

Like that only your first call would be inefficient.

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

  • Comment on Re^3: can sub check context for lvalue vs rvalue context?

Replies are listed 'Best First'.
Re^4: can sub check context for lvalue vs rvalue context?
by perl-diddler (Chaplain) on May 10, 2018 at 06:24 UTC
    I thought of that ... it was tempting, but being extra rigorous w/my stuff, I wanted the values inspected through direct inspection $p->{one} to be consistent with the ones done through the accessor $p->one.

    FWIW, in my case, I don't need to check the value before the assignment, but immediately AFTER the assignment. For example -- wanted to be able to have a URL object where I break it down into proto,site[:port]/path, then, if I assign to $p->path, it would automatically be reflected in $p->url.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-25 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found