in reply to Idiom to return 0 or random number of array elements
If the second parameter for the .. operator is lower than the first parameter, then you'll get no items.my @subset = @array[0 .. int rand(1 + @array)-1];
BTW this will not return a random number of random elements. Instead it'll return the first N elements where N is a random number. If you want random elements, you could shuffle the array first.
|
---|
In Section
Seekers of Perl Wisdom