This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Removing elements after lappend

Old posts that have not been replied to for several years.
Locked
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Removing elements after lappend

Post by Sir_Fz »

I'm using lappend to add nicks to a variable when nick joins, what I want to do is a timer which calls a proc after few seconds and removes this nick from the variable, but I couldn't find out a way to do that. Does anybody have any ideas ?
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: Removing elements after lappend

Post by user »

Sir_Fz wrote:I'm using lappend to add nicks to a variable when nick joins, what I want to do is a timer which calls a proc after few seconds and removes this nick from the variable, but I couldn't find out a way to do that. Does anybody have any ideas ?
Does each person joining have a unique delay before removal? If not: there's no need to keep track of the order/search - just make the timer remove the first element in the list as it will always be the oldest one.

PS: check out my post count :evil:
Have you ever read "The Manual"?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

I mean how to remove an element from a variable, like lappend will add an element but what's the command to remove one ?

for example, I would have something like:

Code: Select all

lappend var($chan) "$nick"
utimer 3 [list rem:nick $nick $chan] ;#which will remove $nick from var($chan)
but what would the proc rem:nick be like ?
user wrote:PS: check out my post count :evil:
lol you're the devil 666 :P
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

check the manual page entries for lreplace and lsearch.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

I tried it before, but I couldn't figure it out.
« Opposing » .tcl set someo "a b c d e"
« bot » Tcl: a b c d e
« Opposing » .tcl lreplace $someo [lsearch $someo b] [lsearch $someo b] ""
« bot » Tcl: a {} c d e
« Opposing » .tcl set someo
« bot » Tcl: a b c d e
as you see the element b is still in the someo variable.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

lreplace doesn't change variables. It takes a list as input and gives a list as output. To have the value stored you must do it yourself. If you want to remove an element, don't specify a replacement value ("" will replace the range with an empty element)
Have you ever read "The Manual"?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Can you please give an example ?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

something like this..

Code: Select all

set wordlist "foo moo bar"
set word "moo"

set index [lsearch -exact $wordlist $word] 
set result [lreplace $wordlist $index $index]
Once the game is over, the king and the pawn go back in the same box.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Thanx :) I finally got it :P
Locked