|
|
| Don't ask to ask, just ask | |
| PerlMonks |
Re: Opening random files then reading random lines from file.by rovf (Priest) |
| on Apr 27, 2012 at 08:21 UTC ( #967545=note: print w/ replies, xml ) | Need Help?? |
|
I see that most part of your question has already been answered. However, one more note about random line selection: Since you need to know the number of the lines in the file, you have to read it at least once. Unless the file is really big, I would therefore slurp the file into an array, and then select a line at random from this array.
UPDATE: I was wrong. As we can see from this comment, it is indeed NOT necessary to slurp the whole file!
-- Ronald Fischer <ynnor@mm.st>
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||