Put the sequences in an array, shuffle the array and then take the first 1000 elements.
Or, taking advantage of the pseudo-random order of the hash-keys:use Modern::Perl; use List::Util qw/shuffle/; my @sequences = (shuffle <DATA>)[0 .. 9]; chomp @sequences; say "@sequences" __DATA__ first second third fourth fifth sixth seventh eight ninth tenth eleventh twelveth thirteenth fourteenth fifteenth sixteenth seventeenth eighteenth nineteenth twentieth
my %sequences = map {chomp; $_ => 1} <DATA>; my @sequences = (keys %sequences)[0 ..9]; say "@sequences";
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
In reply to Re: Extract subset of sequences from a FASTA file
by CountZero
in thread Extract subset of sequences from a FASTA file
by silver_steve
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |