egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

read file randomly

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
neoclust
Halfop


Joined: 14 Aug 2009
Posts: 55

PostPosted: Sun Apr 11, 2010 10:52 am    Post subject: read file randomly Reply with quote

I have a file called bd.dat containing "x" lines, how to read a one line of randomly thanks
Back to top
View user's profile Send private message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Sun Apr 11, 2010 12:41 pm    Post subject: Reply with quote

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

Code:

set output [lindex $filecontent [rand [llength $filecontent]]]
putserv "PRIVMSG $channel :$output"


should do the trick, at least did it for me
Back to top
View user's profile Send private message
TCL_no_TK
Owner


Joined: 25 Aug 2006
Posts: 509
Location: England, Yorkshire

PostPosted: Sun Apr 11, 2010 12:42 pm    Post subject: Reply with quote

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
_________________
TCL the misunderstood
Back to top
View user's profile Send private message Send e-mail
neoclust
Halfop


Joined: 14 Aug 2009
Posts: 55

PostPosted: Sun Apr 11, 2010 4:15 pm    Post subject: Reply with quote

i'm using this proc
Code:

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber