in reply to Re: lvalue substring oddities
in thread lvalue substring oddities
Aside from that, your code is a perfect example of how things can go wrong the way things are. Just saying (prefix = "AB") = "ABC" gets rid of the first '-'; with the proposed change it would leave $foo back in its original state.
Update to respond to Zaxo's update; the "surprise" is exactly the subject of the thread. When you say $foo = substr() = $bar substr returns a magic value that is first stored and then fetched. The "problem" is that both use exactly the same length, even if the store expanded or contracted the string. substr() being replaced by an :lvalue sub is exactly the same case...the sub is called only once but the magic value returned is acted on twice, both times with the originally determined length.
|
|---|