in reply to What is substring working on here.

An lvalue substr as you have there replaces the specified characters in the target string with those that are being assigned, as you can see from your output - however I'm not so sure on the purpose of what it is actually doing in your example.

/J\

Replies are listed 'Best First'.
Re^2: What is substring working on here.
by ikegami (Patriarch) on Jun 09, 2005 at 15:36 UTC

    The two and three arugment forms of substr return an lvalue (something to which one can assign). When something is assigned to this particular lvalue, it triggers some code in perl's guts gets called which causes the original string to be modified.

    I've been told by an esteemed monk or two that the 4 argument form of substr is more efficient than using it as an lvalue.

    Replace
    substr($str, $start, $length) = $new_sub_str;
    with
    substr($str, $start, $length, $new_sub_str);
    for a performance boost.

Re^2: What is substring working on here.
by Scarborough (Hermit) on Jun 09, 2005 at 15:17 UTC
    Its a mess from start to finish and investigation of the orginal code showed the SCL to be incorrect as well. I just didn't understand how this worked at all. Thanks for you help.