Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

darobin (1316)

  (email not shown publicly)

Journal of darobin (1316)

Sunday October 07, 2001
08:31 PM

The Perl Cookbook 8.7

[ #909 ]

The Perl cookbook that we all know is often a great source of take-away code to inject here and there in an incomplete script or module.

However when I read entry 8.7 Randomizing All Lines (in files) that says the solution is to slurp the entire file into an array, shuffle it (using their excellent shuffling sub), and write it out, I couldn't help *coughing*... I've got a ~3Go file the lines of which I need to shuffle, and somehow I was hoping for a more realistic solution :-)

Oh well, it still is a great book. I eventually found my own (non-generic solution, I didn't go the seek()ing way) by using the fact that each line had a date and shuffling the dates and hours, then shuffling the lines accordingly in several passes.

I couldn't find a generic line shuffling module on CPAN, so if anyone out there knows of one or feels like writing one then please let me know ! The best would be one that would call a callback before writing each shuffled line out so that it can be modified (I'm falsifying lost httpd logs...)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.