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 reply to Re^2: can sub check context for lvalue vs rvalue context?
by perl-diddler
in thread can sub check context for lvalue vs rvalue context?
by perl-diddler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |