Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: array splicingby David Caughell (Monk) |
on Jan 30, 2004 at 05:19 UTC ( [id://325140]=note: print w/replies, xml ) | Need Help?? |
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:
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.
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, P.S.
You can read about the functions here: http://www.perldoc.com/perl5.8.0/pod/perlfunc.html
In Section
Seekers of Perl Wisdom
|
|