in reply to Re: Can you set a character in a string at a given index directly?
in thread Can you set a character in a string at a given index directly?

How come the LENGTH parameter is 0? The doc says "removes the elements designated by OFFSET and LENGTH from an array". I'm removing 1 element.
  • Comment on Re^2: Can you set a character in a string at a given index directly?

Replies are listed 'Best First'.
Re^3: Can you set a character in a string at a given index directly?
by Athanasius (Archbishop) on Feb 03, 2015 at 16:46 UTC

    Oh, OK, I thought you were inserting a string at the given position. To replace N characters, of course you set the LENGTH parameter to N. For example, to remove 1 element, set LENGTH to 1.

    And (just for the sake of completeness), if you want to overwrite the string, you can do this:

    splice @chars, $pos, length $insert, $insert;

    which will, for example, take inputs of aaacccddd 3 bbb and thequickbrownfox 8 white, and produce outputs of aaabbbddd and thequickwhitefox, respectively.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,