On 12 Jun 2001 10:08:25 -0400, Charles Lu wrote:
> Functions like pop(), push() allow you to add or remove one element to or
> from a list. Is there a function that allows you to add or remove "X"
> number of elements where "X" > 1?
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
<snip href="perldoc -f splice">
splice ARRAY,OFFSET,LENGTH,LIST
splice ARRAY,OFFSET,LENGTH
splice ARRAY,OFFSET
splice ARRAY
Removes the elements designated by OFFSET and
LENGTH from an array, and replaces them with the
elements of LIST, if any. In list context,
returns the elements removed from the array. In
scalar context, returns the last element removed,
or "undef" if no elements are removed. The array
grows or shrinks as necessary. If OFFSET is
negative then it starts that far from the end of
the array. If LENGTH is omitted, removes
everything from OFFSET onward. If LENGTH is
negative, leaves that many elements off the end of
the array. If both OFFSET and LENGTH are omitted,
removes everything.
</snip>
<code>
#!/usr/bin/perl -w
use strict; #make me behave
my @array = qw(one two this will be removed three four);
splice @array, 2, 4;
print "@array\n";
splice @array, 2, 0, qw(this will be added);
print "@array\n";
</code>
<output>
one two three four
one two this will be added three four
</output>
--
Today is Pungenday, the 17th day of Confusion in the YOLD 3167
Wibble.