Firstly, a slice is just a set of elements of an array. In other words, if you want the first 5 and last 5 members of a class of 100 people, you would write:
my @smalllist = @biglist[0 .. 4, 95 .. 99];
Note that while using a slice you access an array as a list (@) rather than a scalar($).
Using a slice keeps the @biglist the same as when you started. If you want to trim off the @biglist to eliminate the people in the @smalllist from it, you could use a splice() function call to do it.
my @smalllist = splice(@biglist,0,5), splice(@biglist,-5,5);
Mostly, the reason that you would use splice() is just because it's a quick way of getting rid of the elements of a list as you use them, especially when you're using them in a unusual order or in sizes other than 1.
The Offset means where you start your splice from, and either refers to a position away from the start of the list (if you use a positive number) or away from the end of the list (if you use a negative number).
Length is how many elements you're going to cut away from the list.
Hope this helps,
Dave.
P.S.
When I was first learning Perl, I was very excited about how flexible the functions were, and I read quite a bit of the perlfunc document. You might want to try that. Afterwards, though, I read Programming Perl (which I still don't fully understand). It's a challenging read, but worth it. If you only read up on the functions, you won't see the full power of the language.
You can read about the functions here: http://www.perldoc.com/perl5.8.0/pod/perlfunc.html
In reply to Re: array splicing
by David Caughell
in thread array splicing
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |