Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: How do I pick a random line from a file?

by vroom (His Eminence)
on Jan 09, 2000 at 11:00 UTC ( [id://1913]=note: print w/replies, xml ) Need Help??


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];

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1913]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-18 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found