in reply to Pick random item from list of unknown length?
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;
|
|---|