# $EPIC: splice.txt,v 1.3 2007/03/02 02:32:04 jnelson Exp $
$splice(<variable name> <index> <count> [<text>])
Whew. The above technical description is a mouthful and is very confusing. In practical terms, what this function does is “splice” a variable by removing some words from the variable and pasting in other words in their place. It will remove <count> words starting at word <index> (counting from zero, of course), and put <text> in their place. You can chop off the end of a string by using an unreasonably large value of <count>. You can start counting from the end of the string by using a negative <index>. The return value of the function is the text that was removed from the variable.
When you get down to the bottom line, you can use this function to change one or more words in a function without having to rewrite the whole thing. If you have a word index returned by the matching functions, you could use it to search-and-replace words in a variable.
The <index> through <index>+<count>th (counting from 0) words from the variable $<variable name>. As a side effect, the <index> through <index>+<count>th words in $<variable name> are replaced with <text>. If any error occurs, $<variable name> is UNCHANGED.
@ foo = [one two three four five] $splice(foo 1 3 foo bar blah) returns "two three four" $splice(foo 0 2) returns "one foo" $splice(foo 2 1) returns "five" echo $foo shows "bar blah", end result