| View previous topic :: View next topic |
| Author |
Message |
The_Deputy Voice
Joined: 18 May 2007 Posts: 2
|
Posted: Fri May 18, 2007 10:02 am Post subject: Search in file |
|
|
Hello,
I have a file which contains a kind of addressbook eg:
1 Robert Cook Road_Seven_98 Beverly_Hills 081023445
2 Peter Cook Road_Seven_98 Beverly_Hills 08934752435
end so on.
The format of this file is Identifier [SPACE] Firstname [SPACE] Lastname [SPACE] Address [SPACE] City [Space] Phonenumber
I'd like to have an IRC script which provide me the info of a person based on the identifier by example in IRC i do /msg botnick address1 and that the bot answers with the line 1 of the file
Could anyone help me, I'm not a TCL specialist and I get stuck after trying several things |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Fri May 18, 2007 11:06 am Post subject: |
|
|
I guess you could approach this in several different ways, I'd suggest you open the file and read it line by line, using a "while {![eof $fid]} {.." loop.
Then split each line into a list, and use lindex to extract the identifier number. If it matches, print the line, otherwize move on to the next line. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
The_Deputy Voice
Joined: 18 May 2007 Posts: 2
|
Posted: Mon May 21, 2007 4:36 am Post subject: |
|
|
At this moment I have this code which give me all the lines printed out
set in [open "filename.dat" r]
set line [split [read $in] \n]
close $in
puts [lindex $line]
so after the close command I have to search with the index I guess
How can I do this ?
On the internet isn't much information on learning tcl scripting  |
|
| Back to top |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Mon May 21, 2007 12:16 pm Post subject: |
|
|
In this case it'd be a matter of using a foreach-loop to iterate through the list of lines.
Within that loop, split the current line into a list, and use lindex to extract the id number. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
|