07-22-2017, 00:32 +0200
AuthorPost
thommey  03-31-2005, 11:33   | [EGG] Random line from a file Jabber
(Administrator)
Member since 03/2004
62 Posts
                                                                                                                              
01
02
03
04
05
06
07
08
09
10
# Returns a random line out of $file (error if it doesnt exist)
proc randline {file} {
    set fs [open $file r]
    set data [read $fs]
    close $fs
    # Now we have the complete content of $file stored in $data
    set data [split $data \n]
    # Now it's a list of lines, and we use eggdrop's "rand" function to get a random element from it (and return it)
    return [lindex $data [rand [llength $data]]]
}

This post was edited 1 times, last on 08-12-2009, 21:11 by thommey
nazeeb  04-13-2011, 10:59   | Regarding Line extraction
nazeeb
Member since 04/2011
1 Post
Location: India
what if I need to extract a specific line from the file
that is my file contains lines starting from $$, $#, $. and so on......
However there are some other lines where in am interested to extract and put into another file......
heartbroken  01-11-2012, 18:21   | re
Member since 01/2012
5 Posts
hi

thommey i've seen these kinda random reader codes before but i wonder how a code read within a txt file line by line .not random...

can you show an example code for about this please.
for an example if i want my bot posts a poem in poems.txt,bot should be post this line by line on channel how its possible to creat a code for that.
This post was edited 1 times, last on 01-11-2012, 18:23 by heartbroken
CyBex  01-11-2012, 23:27   Jabber  ICQ  AOL IM  Yahoo IM  MSN  Homepage
nie da
(Administrator)

Avatar

Member since 01/2004
260 Posts
Location: Berlin

mfG CyBex @ QuakeNet, UnderNet, EFNet, Freenode, euIRC, GameSurge & ShadowWorld - Files
heartbroken  01-15-2012, 12:39   | hey
Member since 01/2012
5 Posts
hi

/me Thanks to you CyBex :)
Advanced options for this topic:

Ignore this topic (Do not list this topic in the "unread topics" search. You are currently not ignoring this topic.)
Hide this topic (Hidden topics are not displayed in the topics list. This topic is currently not hidden.)
Go to forum

Unclassified NewsBoard 1.5.3-d | © 2003-4 by Yves Goergen