http://www.perlmonks.org?node_id=1913


in reply to How do I pick a random line from a file?

Another more obvious way, but possibly memory intensive way would be to read the entire file into an array and then pick a random element.
open FILE, "<$file" or die "Could not open $file: $!\n"; @array=<FILE>; close FILE; $randomline=$array[rand @array];