in reply to array splicing
you can dofor my $x (@list) { do something with $x }
Of course, the latter destroys the list as it iterates over it.while (my ($x,$y) = splice(@list, 0, 2)) { do something with $x and $y }
Did you have specific questions about offset and length that aren't answered in the fine manual?
With the above while loop, changing to splice(@list, -2) will grab $x and $y off the end of the array instead of the beginning (though that way will die if @list has an odd number of elements instead of just getting an undef $y).
May I suggest a super search of splice to see many different ways of using it?
Update: said slice where meant splice.
|
|---|