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.

Some help pleez if possible

Old posts that have not been replied to for several years.
Locked
[
[Nero]
Voice
Posts: 29
Joined: Mon May 27, 2002 8:00 pm

Post by [Nero] »

Could someone tell me why i keep getting "Invalid idx" with this bit of script, please, Many thanx

proc postsite {nick idx uhost arg} {
global botname chan templist lasttempsite isopen tempnumber
if {$isopen == 0} {
putserv "NOTICE $nick : Please Read the Topic !!, $botname is Currently Closed, Try Again Later."
return 0
} else {
puthelp "PRIVMSG $chan :razz:ossible new Site <$tempnumber> by $nick"
putserv "NOTICE $nick : Please Wait While an OP Checks your Site Number <$tempnumber>"
putdcc $idx "OPS Check this site Pleez"
}
}
[
[Nero]
Voice
Posts: 29
Joined: Mon May 27, 2002 8:00 pm

Post by [Nero] »

Ive Sussed it Myself,
can anyone tell me how to search a text file for a string ?? please
P
Petersen
Owner
Posts: 685
Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK

Post by Petersen »

with grep
[
[Nero]
Voice
Posts: 29
Joined: Mon May 27, 2002 8:00 pm

Post by [Nero] »

LOL - no im looking for a bit of script that will search a url list for a specific url
P
Petersen
Owner
Posts: 685
Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK

Post by Petersen »

and still, the easiest way is with grep. file reading in tcl is inefficient at the best of times, so why do it when you don't have to?
[
[Nero]
Voice
Posts: 29
Joined: Mon May 27, 2002 8:00 pm

Post by [Nero] »

I understand what your saying & have looked at grep but its too big just to look in a text file to see if the url that i want to add is already in the text file, but thank you for your help though, i appreciate it
P
Petersen
Owner
Posts: 685
Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK

Post by Petersen »

catch {exec grep -i $url $file}

whats so big about that? returns 1 if nomatch, 0 if match
[
[Nero]
Voice
Posts: 29
Joined: Mon May 27, 2002 8:00 pm

Post by [Nero] »

I think were at differenty posts here i was looking at the Grep Scripts.
what i need is ...
I have a list of urls in a .txt file
i want users to be able to add urls to the .txt file via my tcl script but i want the tcl to check to see if the submitted url is in the list already if so, say in the channel that its a dupe, if it isnt in the .txt file then add it, is that possible in tcl ??

I thought this would work but it wont find the dupe although the dupe is in the templist.txt

set file templist
set found 0
set fs [open $file r]
while {![eof $fs]} {
gets $fs line
if {$line == $nick} { set found 1 }
}
close $fs
if {$found} {
puthelp "PRIVMSG $chan : was found!"
} else {
puthelp "PRIVMSG $chan : was not found."
}
Thanx again

<font size=-1>[ This Message was edited by: [Nero] on 2002-06-04 14:50 ]</font>
P
Petersen
Owner
Posts: 685
Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK

Post by Petersen »

and as I keep saying, use grep, cos tcl's file handling is crap

set file templist
if {![catch {exec grep -i $url $file}]} {
puthelp "PRIVMSG $chan : was found!"
} else {
puthelp "PRIVMSG $chan : was not found."
}

User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Petersen, what are you talking about?? Tcl has great file handling.

Nero, you need something like this:

Code: Select all

# Returns -1 if not found, otherwise it's a dupe
proc scan_tempfile {url} {
  set fp [open tempfile r]
  set lines [split [string tolower [read $fp]] n]
  close $fp
  return [lsearch -exact $lines [string tolower $url]]
}

if {[scan_tempfile "http://hotsheep.com"] == -1} {
  putserv "privmsg somechan :that's a dupe :("
} else {
  putserv "adding to file..."
  blah blah
}
P
Petersen
Owner
Posts: 685
Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK

Post by Petersen »

try running that script on a 500meg file and see what I mean :razz:
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

I see. Well, that's less Tcl's fault than the algorithm you use to scan through the file. The Tcl file api (gets, read, puts, seek, tell, eof, etc) is pretty much the same as any other language's, including C's. I doubt his file is 500 meg though, so the algorithm isn't very important :)
P
Petersen
Owner
Posts: 685
Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK

Post by Petersen »

yes, then you could use a sequential read, eval, readnext algorithm, but I guarantee it won't be anywhere near the speed of a pure c implemenation, simply due to the overhead of the interpreter running in a while loop. Using external pure c modules (such as grep) in my mind is always preferable than using the scripted alternative. Yes, in this case, the performance increase is probably negligable, but thats no reason not to code it the most efficient way possible (well, technically, the most efficient way would be to build a simple grep as a tcl module, but thats going a little to extreme just to avoid the overhead of exec)
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Ah I see, you mean Tcl's file performance is crap. When you said "file handling" I thought you meant the api. Yeah, Tcl is obviously much slower than C.

But anyway, unless you have thousands of url's to check, my way is still faster than exec grep. It also won't interfere with process limits on your shell. And it's always gonna be more portable :)

On the performance issue, I think one should note that grep is also going to be slow on a 500 meg file. When you get to the point of having such a large file, you should use a real database like mysql, not a flat text file and grep.
P
Petersen
Owner
Posts: 685
Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK

Post by Petersen »

well yah, once you get to that size of unindexed sequential file everything is gonna be slow. grep is still quicker than tcl though :razz:
Locked