Perl Home
PERL Functions
© 2011 TutorialsPoint.COM
|
PERL splice Function
Syntax
splice ARRAY, OFFSET, LENGTH, LIST
splice ARRAY, OFFSET, LENGTH
splice ARRAY, OFFSET
|
Definition and Usage
Removes the elements of ARRAY from the element OFFSET for LENGTH elements, replacing the elements removed with LIST, if specified. If LENGTH is omitted, removes everything from OFFSET onwards.
Return Value
In scalar context undef if no elements removed
In scalar context last element removed
In list context empty list on failure
In list context list of elements removed
Example
Try out following example:
#!/usr/bin/perl -w
@array = ("a", "e", "i", "o", "u");
@removedItems = splice(@array, 0 , 3, ("A", "E", "I"));
print "Removed items: @removedItems\n";
|
It will produce following result:
|

|
|
|