in reply to Re: can sub check context for lvalue vs rvalue context?
in thread can sub check context for lvalue vs rvalue context?
What would your wantlvalue return if called this way: @x = x() = 5;?
I think operator associativity can help answer that one:
$ perl -MO=Deparse -e ' @x = x() = 5; ' @x = (x() = 5);
So I'd say that x() is primarily in lvalue context here. And what's being assigned to @x is not the return value of x(), but the return value of the assignment operation, which is an lvalue itself.
$ perl -le 'sub x : lvalue { $a } (x() = 4) = 2; print $a' 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: can sub check context for lvalue vs rvalue context?
by BrowserUk (Patriarch) on May 09, 2018 at 15:15 UTC | |
by haukex (Archbishop) on May 10, 2018 at 11:20 UTC |