To reply to your sub :lvalue case, the index shouldn't be kept from one call to prefix() to the next with either the existing or proposed behaviour. However there is a bug (#24200) with substr used in an :lvalue sub. That bug should be fixed whatever else happens. (The bug is that rvalue calls to the sub will not work correctly after the first lvalue call.)

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.


In reply to Re: Re: lvalue substring oddities by ysth
in thread lvalue substring oddities by ysth

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.