* How do I select a random line from a file?
added mention of File::Random Index: perlfaq5.pod =================================================================== RCS file: /cvs/public/perlfaq/perlfaq5.pod,v retrieving revision 1.23 diff -u -d -r1.23 perlfaq5.pod --- perlfaq5.pod 25 Aug 2002 20:10:29 -0000 1.23 +++ perlfaq5.pod 29 Aug 2002 03:44:45 -0000 @@ -987,6 +987,12 @@ in. You can find a proof of this method in I<The Art of Computer Programming>, Volume 2, Section 3.4.2, by Donald E. Knuth. +You can use the File::Random module which provides a function +for that algorithm: + + use File::Random qw/random_line/; + my $line = random_line($filename); + Another way is to use the Tie::File module, which treats the entire file as an array. Simply access a random array element.
