Found this inside a loop. I’ve read up about splice but it just confused me more.
I’m not familiar with Perl, but am trying to translate an algorithm to another language.
my $sill = splice(@list,int(rand(@list)),1);
last unless ($sill);
To be more specific: What will be inside $sill if it doesn’t exit the loop from the last?
Thanks for any help!
This randomly removes one element from the array
@list. That value is assigned to$sill. If that was a false value, the enclosing loop (not shown) is broken out of.splicetakes an array, an offset, and a length, plus a replacement list. If the replacement is omitted, the elements are deleted.The length is constant (1 element), but the offset is calculated as a random integer smaller between 0 and the length of
@list.