Is there a way to do it more succinctly without creating that temporary array?If you're reading in the file line-by-line, who cares about the extra array?
But say you're reading from some handle, and you want to randomly pick a line:
use Algorithm::Numerical::Sample; my $s = Algorithm::Numerical::Sample::Stream->new; while (<>) { $s->data($_): } my $random = $s->extract;
In reply to Re: Pick random item from list of unknown length?
by JavaFan
in thread Pick random item from list of unknown length?
by Cody Fendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |