splice(@array, 0, 8);
splice destructively removes elements from @array, so you have to ask if you really want to do that. Since you are not splicing elements into the array (like you would splice a rope), splice probably doesn't make sense in this context.
A slice (like you do with pizza or pie, not like a rope) (see below) seems to be what you want, and it is a little more intuitive to read. The splice just accesses the elements, without removing them.
@array[0..8];
The other monks comments on how to do a foreach still apply to. So you can just foreach over a slice. It's better than repeating statements or using a for loop with a counter variable. If you want just part of the array, you can specify the start and stop boundaries of slice using something like @array[1..6]
foreach $item (@array[1..6]) {
$item =~ s/\.//g;
}
So this modifies only certain elements of the array, and it's pretty darn clean to look at. You may to modify the indexes (indices) if 1..6 isn't what you want exactly, but you get the general idea.
|