Problems? Is your data what you think it is? | |
PerlMonks |
Re^2: can sub check context for lvalue vs rvalue context?by perl-diddler (Chaplain) |
on May 09, 2018 at 03:12 UTC ( [id://1214252]=note: print w/replies, xml ) | Need Help?? |
Yeah, returning a tied value is what I was grudgingly working on, as I didn't think it would be very efficient.
I was hoping I could return a non-tied value for rvalue context as 'reading' a var is often a more frequent operation than 'writing' to it. I've used lvalues for many functions, where I don't need to check the value, but do want assignments to structures to be checked for valid member names. I use structures more often than objects, which is why I shook my head at the discouragement against lvalue accessor subs. Of course if you want to do something contingent on value change...then it seems perl only offers a tied-type solution. It's too bad a "wantlvalue" keyword wasn't introduced with lvalue subs -- it would have been at least as useful as 'wantarray'. Imagine all the dual-use functions that return different values based on scalar or array context that would not be do-able w/o knowing return context. It seems that's an equivalent case to knowing whether or not the return context is lvalue or not.
In Section
Seekers of Perl Wisdom
|
|