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;
In reply to Picking Random Lines from a File by de2425
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |