punkish has asked for the wisdom of the Perl Monks concerning the following question:
I have a file with "n" sets of "m" rows (lets assume they are sorted by the token that makes them into a set... so, if the rows have some attributes about people, the first token in each row is the name of the person, and there are "m" rows for, say 'punkish' and another "m" rows for 'paco', and so on). I want to grab random "j" rows from each set and write "n" sets of "j" rows out to another file.
I apologize that I am even unable to offer pseudo code to try and figure it out. It would be trivial to do it in a db, but I wouldn't mind knowing how to do this with just a file and the magic of Perl.
Oh! did I mention that (n * m) is a very large number, that is, we are talking about a file with around 8 million rows.
Update: on second glance, this post should really be titled grabbing random "j" rows from a file... oh well.
Update 2: (after bonking himself on the head for not providing a "compleat" problem the first time)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: grabbing random n rows from a file
by japhy (Canon) on Jul 18, 2006 at 21:57 UTC | |
|
Re: grabbing random n rows from a file
by ikegami (Patriarch) on Jul 18, 2006 at 22:48 UTC | |
|
Re: grabbing random n rows from a file
by GrandFather (Saint) on Jul 18, 2006 at 21:46 UTC | |
|
Re: grabbing random n rows from a file
by Hue-Bond (Priest) on Jul 18, 2006 at 21:58 UTC | |
by ikegami (Patriarch) on Jul 18, 2006 at 22:50 UTC | |
|
Re: grabbing random n rows from a file
by perrin (Chancellor) on Jul 18, 2006 at 21:50 UTC | |
|
Re: grabbing random n rows from a file
by swkronenfeld (Hermit) on Jul 18, 2006 at 21:53 UTC | |
|
Re: grabbing random n rows from a file
by ambrus (Abbot) on Jul 19, 2006 at 08:51 UTC | |
|
Re: grabbing random n rows from a file
by Anonymous Monk on Jul 19, 2006 at 18:41 UTC |