1: Those are added since you are converting the text-line into a list (splitting by newline). Since the text-parameter will always contain a single line, I'm not sure this is what you intended. {} would be added to encapsulate the list item (the text string) whenever it contains any "special" characters or whitespaces that would otherwize interfere with list structures.
2: Searching would be quite possible using various commands such as "string match". Concern must however be taken to whatever format is used when lines were added. I would however suggest adding lines of text, rather than lines of lists.
Also, your foreach-list is flawed, as you use the variable "text" within the loop rather than the iterated variable "line". Furthermore, you'd be better off opening and closing the file outside the loop.
Even further, & is "bit-wize and-operator", and is not recommended for logical comparisons, use && instead. Also considder using "string equal" to allow non case-sensitive comparisons.
Finally, as stated in answer to q; "text" will always contain one single line, so using that foreach-loop along with splitting is completely pointless.
I'd suggest something like this instead:
Code: Select all
bind pubm - "*" pub_write
proc pub_write {nick uhost hand chan text} {
set text [stripcodes bcruag $text]
if {[string equal -nocase $nick "Blub"] && [string equal -nocase $chan "#testchan"]} {
set fileId [open test.txt "a"]
puts $fileId $text
close $fileId
}
}
Searching in this case would be a matter of opening the file, read one line at a time using gets, and check it against your credentials..
Another option might be to open it and read all data using the "read" command, then split the data on newlines, and use lsearch..