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.

weird

Old posts that have not been replied to for several years.
Locked
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

weird

Post by caesar »

bind dcc n test task:test

proc task:test { hand idx arg } {
set list "Monday, 27 January 2003"
set index [lsearch -exact $list Monday]
set list [lreplace $list $index $index foo]
putlog "List: $list"
}

And I still get as a result: 'foo Monday, 27 January 2003' instead 'foo, 27 January 2003'. I'm missing something?
Once the game is over, the king and the pawn go back in the same box.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

The problem is all down to the fact, you are not working on a list, and you are using exact matching.

While there is nothing legaly wrong (in terms of differance between string and list) with the value of $list, the values arr as follows

Code: Select all

foreach item $list {
  puts stdout "Item: $item"
}
produced
Item: Monday,
Item: 27
Item: January
Item: 2003
Note the coma?

"lsearch" does an exact search (By the way, -exect and glob are the same, only wildcards are not translated, which saves CPU. However, passing "Monday" in both -exact and -glob modes works the same), for monday, and doesn't find it. So it returns -1 to the valud of $index.

Using -1 as the index in replace, causes the item to be prepended, and doesn't replace a thing.

If you searched for "Monday,", all would work fine.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

I guess because of the lil ',' next to the Monday.. Anyway, found an easier solution for this: set list [join [lreplace [split $list] 0 0 moo,]] and this dose the trick. Thanks to the 'Forum Search' thingy :)
Once the game is over, the king and the pawn go back in the same box.
Locked