
perlplexer
Deleted
Nov 22, 2000, 11:03 AM
Post #2 of 6
(853 views)
|
$sth = $dbh->prepare( qq{ SELECT foo, bar FROM table;} ); $sth->execute; while((@row=$sth->fetchrow_array)?@rl=@row:0){ last if rand(length $row[rand($#row)]) < 0.5*(length $row[rand($#row)]); } print "Random line: @rl\n" @rl is your random line... You can play with the condition a bit more though... or just do SELECT count(*) from table; and then use the value returned by that SQL statement in rand(); or use fetchall_arrayref() to fetch all rows, determine size of the resulting array and get a random line from it... perldoc DBI is your friend. :)
|