[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Perl's splice function, a newbie query



Regarding Perl's splice function, the Camel book says:

--- quoted from the book ---

splice

splice ARRAY, OFFSET, LENGTH, LIST
splice ARRAY, OFFSET, LENGTH
splice ARRAY, OFFSET

This function removes the elements designated by OFFSET and
LENGTH from an array, and replaces them with the elements
of LIST, if any. The function returns the elements removed
>from the array. The array grows or shrinks as necessary. If
LENGTH is omitted, the function removes everything from
OFFSET onward.

--- end quote from the book ---

I am a Perl newbie. I have been puzzled by several features
of this function. Could someone please confirm or refute my
impressions, listed below:


* If LENGTH is 0 (zero), the function removes nothing.
* OFFSET can be either a positive or negative number 
  (such as 1 or -2);
* LENGTH can be only a positive number 
  (1 or 2 or 3, etc.);
* OFFSET does NOT refer to a particular subscript of the 
  specified array (an offset of 3 does NOT refer to the 
  fourth element of a zero-base-indexed array);
* OFFSET does NOT refer to a particular element of the 
  specified array (specifying an offset of 3 does NOT 
  refer to the third element of the array);
* OFFSET DOES refer to the "nothing" BETWEEN two elements 
  of the specified array (Is this true?);
* an OFFSET of 0 (zero) refers to the "nothing" before 
  the first element of the specified array, and an OFFSET 
  of -1 refers to the "nothing" between the last two elements 
  of the specified array.

I hope that someone will briefly confirm or refute my
impressions of this function. Thank you. If there is a more
appropriate forum for such (general Perl, rather than
specific MacPerl) questions, please suggest it to me-- ;-)

Steve Doonan, New Mexico, US



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch