egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Search in file

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
The_Deputy
Voice


Joined: 18 May 2007
Posts: 2

PostPosted: Fri May 18, 2007 10:02 am    Post subject: Search in file Reply with quote

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
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Fri May 18, 2007 11:06 am    Post subject: Reply with quote

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
View user's profile Send private message
The_Deputy
Voice


Joined: 18 May 2007
Posts: 2

PostPosted: Mon May 21, 2007 4:36 am    Post subject: Reply with quote

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 Sad
Back to top
View user's profile Send private message
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Mon May 21, 2007 11:15 am    Post subject: Reply with quote

Beginners Guide to TCL
_________________
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Back to top
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Mon May 21, 2007 12:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber