SUNiNET - Your Eggdrop & TCL resources site
[ Home Eggdrop TCL Links About ]

Guide to TCL scripting for Eggdrop 1.6


[ Previous ] [ Index ] [ Next ]


8.6 Replacing objects in a list

You can also replace objects in a list. For this we use the command lreplace.
The syntax of a lreplace command is lreplace <list> <start number> <end number> [object(s)].

The <list> is the list from which the objects must be retrieved just like with the lindex command.

The <start number> is the number of the object from where the command should start replacing objects in the list.
The numbering of the objects works in the same way as they do in the lindex command.

The <end number> is the number of the object at which the command should stop replacing objects in the list.
Instead of a number you can also use the word end. This makes the command replace the objects from the given start object until the end of the list.

The [object(s)] is with what you want the command to replace the above given objects.
If you don't specify anything to replace the above objects with, they are removed from the list.
Note that this also has to be a valid list on its own.

A small example: lreplace $test 3 7 "foo" "bar" returns the list with the objects 4 through 8 replaced with the objects "foo" and "bar" or lreplace $test 4 end would return the list with the objects 5 and up until the end of the list removed from it.

The lreplace command outputs a newly compiled list with the replaced objects you choose, leaving the open and close braces that mark the start and stop of an object which were already in the list intact and adds new ones if neccesary.


[ Previous ] [ Index ] [ Next ]


Design & Graphics by Shawn Borton
Copyright © 2000-2005 Marijn van Zon