|more useful options|
This proved to be the final piece in my puzzle. Instead of passing an lvalue ref to a selected substring into deeper levels of recursion, I have to pass the (aliased) target string, and the start/end pair of teh selectd substring. The deeper level can then use substr to modify the appropriate bit of the target without falling into the trap of re-using a modified lvalue ref.
Passing the three salient pieces of information around separately is less convenient that doing so nicely encapsulated in the lvalue ref, and it forces me to do the math of combining the start-end pair passed at a given level with the start-end pair selected from within it, before passing them in deeper.
It also forces me to manipulate the start/end pair I receive to account for any shrinkage or growth of the selection made at this level or any deeper levels called from this level--within my caller.
Perfectly doable at this level, but it would also be perfectly doable--and more efficient and convenient--if Perl did that for me. I've no doubt that it could be done by Perl given the interest of someone with sufficient tuits at that level.
Perhaps the most diconserting thing about this whole thread is that Perl is silently converting an lvalue ref to a normal scalar when a second modification through it is attempted, and thus discarding the changes made by that second change!
That ought to be a red-flag. Maybe it should be the subject of a perlbug?
Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.
In reply to Re^3: Scalar refs, aliasing, and recursion weirdness.