in reply to Opening random files then reading random lines from file.
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Opening random files then reading random lines from file.
by choroba (Cardinal) on Apr 27, 2012 at 08:39 UTC | |
by brx (Pilgrim) on Apr 27, 2012 at 09:18 UTC | |
by rovf (Priest) on Apr 30, 2012 at 08:42 UTC | |
|
Re^2: Opening random files then reading random lines from file.
by JavaFan (Canon) on Apr 27, 2012 at 08:59 UTC | |
|
Re^2: Opening random files then reading random lines from file.
by fame (Initiate) on Apr 27, 2012 at 19:07 UTC | |
by Anonymous Monk on Sep 11, 2012 at 15:08 UTC | |
by jdporter (Paladin) on Sep 11, 2012 at 17:26 UTC |