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.

File search problem

Help for those learning Tcl or writing their own scripts.
Post Reply
i
iNFERiON
Voice
Posts: 7
Joined: Sat Nov 13, 2004 4:23 pm

File search problem

Post by iNFERiON »

I am writing a script that is supposed to search trough a file on the server and check if a string given by the user exists in it, if so, it should output it. So far, with the help of greenbear on IRC I got this:

Code: Select all

		set query [lrange $text 1 end]
		set query [string map {" " "\*"} $query]
		set srcdb [open users.txt r]
		set data [read -nonewline $srcdb]
		close $srcdb
		set lines [split $data "\n"]
		foreach line $lines {
			 if {[string match -nocase "*$query*" $line]} {
			 	putmsg $chan $line
			 } else {
			 }
		}
However it does not output any results even if I try it with a query I'm 100% sure is in the database. What am I missing here ?
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

2 questions:
- why do you use lrange? it looks pointless in your script, since it a) uses a list operation on a string and b) ignores the first entry. esspially the functionality b) could be the cause of your "little problem" ;).
- why do you escape the *? there is no need to :D. Another tip... if files always have 1 "whitespace" character, you might want to use ? instead of * depending on the exactness the result should be :D.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Post Reply