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.

Questions and more questions.

Help for those learning Tcl or writing their own scripts.
Post Reply
L
Lu5ck
Halfop
Posts: 43
Joined: Thu Dec 07, 2006 8:58 am

Questions and more questions.

Post by Lu5ck »

Hi there,

I wanna ask is -exact of lsearch case sensitive? If it is, what option should I choose not to have the case sensitivity. Thank you.

I also got question regarding the file operation. If I wanted to update the file with the data from variable call "$data" which is a list. What should I do if I want to skip the first few line of the file from been overwrite. Thank you.

Regards,
Lu5ck
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: Questions and more questions.

Post by user »

If you have questions about particular commands, check the manual. There's no -nocase option in the latest stable release, so your best bet is to do a case insensitive regexp match

Code: Select all

lsearch -regexp $list {(?i)yourword}
or convert everything to lower-/uppercase before doing the search.
Have you ever read "The Manual"?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

It is case sensitive, and unfortunately, there is no documented option to make it non-case sensitive.

Make sure you open the file in append-mode, such that it is not truncated and the write pointer is at the end of the file. Ex:

Code: Select all

set fid [open "myfile" "WRONLY CREAT APPEND"]
See the manual page for open other options.
NML_375
L
Lu5ck
Halfop
Posts: 43
Joined: Thu Dec 07, 2006 8:58 am

Post by Lu5ck »

Hi there,

Thanks. I want to ask about "bind time * <function>" as well. If I indicate it as *, how often will the function be run?

Regards,
Lu5ck
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Once every minute
NML_375
L
Lu5ck
Halfop
Posts: 43
Joined: Thu Dec 07, 2006 8:58 am

Post by Lu5ck »

Hi there,

Thanks.

Regard,
Lu5ck
L
Lu5ck
Halfop
Posts: 43
Joined: Thu Dec 07, 2006 8:58 am

String map

Post by Lu5ck »

Hi there,

I got question about "string map" command. I don't know how it work, the documentation is confusing for me. I assume that you can have many replacement in string map right? But I still kinda confused.

Regards,
Lu5ck
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

It can indeed handle multiple replacements at once.
In order to achieve this, create a list with odd numbered elements being the key to look for, and even elements being what to replace it with. Order is of importance in some cases, as string map will scan the list and stop at the first match (ai needs to come before a, otherwize a will always make the match).
A simple example of a "map":

Code: Select all

set map [list "oldword1" "newword1" "oldword2" "oldword2" ...]

set map [list "aibo" "cool dog" "ai" "artificial intelligence" "a" "the letter a"]
You could also build this map using arrays and "array get", however, keep in mind that the order is not fixed when using "array get".

Code: Select all

set mymap(oldword1) "newword1"
set mymap(oldword2) "newword2"
set map [array get mymap]
NML_375
Post Reply