#!/usr/bin/perl
use strict;
use warnings;
my @array = ( 1..20 );
my @array2 = ( 1000..1005 );
print "\@array : @array\n\@array2 : @array2\n";
my @rmArray = splice ( @array, 5, scalar(@array2), @array2 );
print "After spliece\n";
print "\@array : @array\n\@rmArray : @rmArray\n";
Result :
$ perl splice.pl
@array : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
@array2 : 1000 1001 1002 1003 1004 1005
After spliece
@array : 1 2 3 4 5 1000 1001 1002 1003 1004 1005 12 13 14 15 16 17 18 19 20
@rmArray : 6 7 8 9 10 11
perl -e ' @an = ('a','b','c'); splice(@an,1,1); print "@an\n";
a c
andre@T3500:~> perl -e ' @an = ('a','b','c','d','e'); splice(@an,3,1); print "@an\n"; '
a b c e
andre@T3500:~> perl -e ' @an = ('a','b','c','d','e'); splice(@an,2,2); print "@an\n"; '
a b e
andre@T3500:~>
Syntax: splice (array to be modified, early modification, amount of values to be inseritdo, values to be insert)