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.

read file randomly

Help for those learning Tcl or writing their own scripts.
Post Reply
n
neoclust
Halfop
Posts: 55
Joined: Fri Aug 14, 2009 11:03 am

read file randomly

Post by neoclust »

I have a file called bd.dat containing "x" lines, how to read a one line of randomly thanks
r
raider2k
Op
Posts: 140
Joined: Tue Jan 01, 2008 10:42 am

Post by raider2k »

after you read all of a files content into a list:

Code: Select all

set output [lindex $filecontent [rand [llength $filecontent]]]
putserv "PRIVMSG $channel :$output"
should do the trick, at least did it for me
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

:arrow: try Search feature. or just look at the other forums :idea:

The post your after is here http://forum.egghelp.org/viewtopic.php?t=6885 under TCL Help
n
neoclust
Halfop
Posts: 55
Joined: Fri Aug 14, 2009 11:03 am

Post by neoclust »

i'm using this proc

Code: Select all

proc readfile {min hour day month year} {
    global filenews
    foreach chan [channels] {
    if {[channel get $chan randnews]} {
    set file [open $filenews r]
    set data [read $file]
    close $file
    set lines [split $data \n]
    set randline [lindex $lines [rand [llength $lines]]]
     putserv "PRIVMSG $chan :$randline"
     }
    }
 }
Thanks
Post Reply