Replace the second and third elements.
# The splice function returns the elements it removes
#!/usr/bin/perl -w
@array = (1,2,3,4,5,6,7,8,9);
print "@array\n";
$offset = 1;
$length = 2; # two elements.
splice(@array, $offset, $length, 99, 98, 97, 96);
print "@array\n";
Related examples in the same category