de2425 has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to get a program to randomly pick 300 lines from a text file. I am getting output but I'm getting 300 lines that are exactly the same. Would anyone be able to help me and tell me what I'm doing wrong here? I would so appreciate it.
use strict; use warnings; open (OUT, ">c:/work/250/250_random.txt"); open (IN, "c:/work/250/Master_file.txt"); $size=300; $count = (); while (<IN>){ while ($count<=$size){ rand($.)<1 && ($line=$_); print OUT $line; $count++; } } close IN; close OUT;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Picking Random Lines from a File
by bart (Canon) on Oct 09, 2008 at 18:45 UTC | |
|
Re: Picking Random Lines from a File
by ikegami (Patriarch) on Oct 09, 2008 at 17:33 UTC | |
|
Re: Picking Random Lines from a File
by JavaFan (Canon) on Oct 09, 2008 at 20:35 UTC | |
by nathanroy (Initiate) on Apr 21, 2009 at 20:20 UTC | |
|
Re: Picking Random Lines from a File
by toolic (Bishop) on Oct 09, 2008 at 17:45 UTC | |
|
Re: Picking Random Lines from a File
by Illuminatus (Curate) on Oct 09, 2008 at 17:51 UTC | |
|
Re: Picking Random Lines from a File
by Illuminatus (Curate) on Oct 09, 2008 at 17:22 UTC | |
by ikegami (Patriarch) on Oct 09, 2008 at 17:27 UTC | |
by de2425 (Sexton) on Oct 09, 2008 at 17:38 UTC |