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.

Search in file

Help for those learning Tcl or writing their own scripts.
Post Reply
T
The_Deputy
Voice
Posts: 2
Joined: Fri May 18, 2007 9:52 am

Search in file

Post by The_Deputy »

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
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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
T
The_Deputy
Voice
Posts: 2
Joined: Fri May 18, 2007 9:52 am

Post by The_Deputy »

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 :-(
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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
Post Reply