| View previous topic :: View next topic |
| Author |
Message |
manxmistress Voice
Joined: 07 May 2012 Posts: 3 Location: Isle of Mann
|
Posted: Mon May 07, 2012 3:38 am Post subject: Slowing down pasting of a txt file |
|
|
Ok I am ok so far with this but would like to slow down the pasting of each line, what it does is read from a specific txt file and paste on line at a time but is doing so too fast, I would like say 3 or 4 seconds between lines also cant understand why it stops before the end of each file.
| Code: |
set tracks [open $filename]
set data [split [read -nonewline $tracks] \n]
close $tracks
foreach trance_line $data {
putserv "PRIVMSG $nick :$trance_line"
}
}
proc Trance_Listing {nick uhost hand text} {
set number "trancelist"
set filename ${::trance_file}/${number}.txt
set tracks [open $filename]
set data [split [read -nonewline $tracks] \n]
close $tracks
foreach trance_line $data {
putserv "PRIVMSG $nick :$trance_line "
}
}
|
|
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Mon May 07, 2012 1:07 pm Post subject: |
|
|
There's quite a few ways of doing this; I'd probably do it using a recursive timers, reading one line at a time from the file.
A short example on how you could do this:
| Code: | proc tellNextLine {target fd} {
if {[gets $fd line] >= 0} {
puthelp "PRIVMSG $target :$line"
utimer 4 [list tellNextLine $target $fd]
} else {
close $fd
}
}
proc Trance_Listing {nick userhost handle text} {
tellNextLine $nick [open "${::trance_file}/trancelist.txt" RDONLY]
} |
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
manxmistress Voice
Joined: 07 May 2012 Posts: 3 Location: Isle of Mann
|
Posted: Mon May 07, 2012 1:25 pm Post subject: |
|
|
| Ok i can see what you mean but i dont have a clue how to put that in what I have, that above the user picks the file name and it starts pasting. It would be helpful to know what to do with that in plain english or how it is in relationship to what I have cheers |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Mon May 07, 2012 1:35 pm Post subject: |
|
|
Sure,
What I do, is rather than having a foreach-loop iterate through all lines at once, I use timers to repeatedly call my proc named "tellNextLine". This proc then reads the next line from the (already opened) file and sends it to the target, and then starts a new timer (to call tellNextLine again), until there are no more lines remaining in the file ("gets" returns less than 0 bytes read). I then close the file to preserve file descriptors.
Also, rather than read the whole file into memory at once, I leave the file open and only read the one line I need at the moment. Since we're using such a slow pace for sending messages, there's no real benefit from caching the texts in memory.
Other than that, I skipped some temporary variables you've used. The code I wrote should be able to completely replace the code from your original post. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
manxmistress Voice
Joined: 07 May 2012 Posts: 3 Location: Isle of Mann
|
Posted: Wed May 23, 2012 4:21 am Post subject: |
|
|
Sorry I didn't get back my sub/hubby been ill after chemo so all is well now including what you did thank you so much,  |
|
| Back to top |
|
 |
|