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?
Well, its easy to demonstrate there is only one call made. So what now?
I think the easiest way to think of it, is that the function returns an lvalue to the calling context; and has no say or knowledge of how that lvalue is used there.
And in reality, that is exactly what happens:
{ my $X = 12345; sub x :lvalue { $X } };; print x();; 12345 $r = \x();; print x();; 12345 $$r = 456;; print x();; 456
Think of a function returning a reference. It does not know and cannot influence whether that reference will be used to read the referent value, or assign a new value to it.
This is analogous; thus even if you knew what the context was, it would not benefit you to know. (Also why :lvalue never made it off the 'experimental' list.)
|
|---|
| 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 07:00 UTC | |
by BrowserUk (Patriarch) on May 10, 2018 at 07:19 UTC | |
by perl-diddler (Chaplain) on May 10, 2018 at 18:54 UTC | |
by BrowserUk (Patriarch) on May 10, 2018 at 19:28 UTC | |
by perl-diddler (Chaplain) on May 10, 2018 at 21:50 UTC | |
| |
by ikegami (Patriarch) on May 11, 2018 at 19:51 UTC |