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 

two problems

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


Joined: 19 Jul 2006
Posts: 12

PostPosted: Wed Jul 19, 2006 10:25 am    Post subject: two problems Reply with quote

OK I am new to TCL scripting, I come from the mirc scripting camp Wink.

I already read some articles about scripting in TCL, but don't find a answer to these two questions.

1. Is there a command like gettok in TCL so you can cut a string lets say:
This-is-a-test

into

This
is
a
test

and access all of these strings seperatly

2. I have a Textfile in which in each line a nickname is. Now I want to search the Textfile for a nick and if it is found that the TCL script do sth.
Back to top
View user's profile Send private message
krimson
Halfop


Joined: 19 Apr 2006
Posts: 86

PostPosted: Wed Jul 19, 2006 10:30 am    Post subject: Reply with quote

1. use [split "This-is-a-test" -]
2. http://tclhelp.net/#faqfile
Back to top
View user's profile Send private message Send e-mail
keeper2
Voice


Joined: 19 Jul 2006
Posts: 12

PostPosted: Wed Jul 19, 2006 10:35 am    Post subject: Reply with quote

krimson wrote:
1. use [split "This-is-a-test" -]
2. http://tclhelp.net/#faqfile


Thanks, but when I have the whole Textfile in data how to search for a specified string?
Back to top
View user's profile Send private message
krimson
Halfop


Joined: 19 Apr 2006
Posts: 86

PostPosted: Wed Jul 19, 2006 11:21 am    Post subject: Reply with quote

you can use something like this
Code:
set openfile [open "path/to/your/file" r]
set data [read $openfile]

foreach line [split $data \n] {
  if {$line == nick1} {
    #perform whatever commands
  } elseif {$line == nick2} {
    #perform other commands
  } else {
    #another set of commands
  }
}
Back to top
View user's profile Send private message Send e-mail
metroid
Owner


Joined: 16 Jun 2004
Posts: 771

PostPosted: Thu Jul 20, 2006 1:18 am    Post subject: Reply with quote

don't forget to close the file.

Code:
set openfile [open "path/to/your/file" r]
set data [read $openfile]
close $openfile

foreach line [split $data \n] {
  if {$line == nick1} {
    #perform whatever commands
  } elseif {$line == nick2} {
    #perform other commands
  } else {
    #another set of commands
  }
}
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