Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading random lines from a text file.

Status
Not open for further replies.

dreamstreet

Programmer
Jan 24, 2003
25
US
Hello,

I have a text file and it contains something like:

text1
text2
text3


I know how to open/read the file but I want to assign the variable $text to random lines from that .txt file.

All I know is how to open/read so far:

open(F,"file.txt");
$text = <F>;

any help? Thanks



d
 
never mind..I got it.

Here's what I used:

open(f,"file.txt");
srand;
rand($.) < 1 && ($text = $_) while <f>;
# $line is the random line


d
 
Hmm... this reminds me of a script I wrote in 4DOS back in the day to hurl random abuse at me instead of the boring "Bad command or file name"...

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top