Tutorials Point


  Perl Home

  PERL Functions

© 2013 TutorialsPoint.COM


  Home     References     About TP     Advertising  

PERL splice Function



Advertisements

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:

Removed items: a e i


Advertisements


  

Advertisements