|
||
|
Using an array as a stack The Perl 'Splice' function
One final function that operates on arrays is the
splice function.This function is used to extract a chunk of data from the middle of an array.
It is important to note that after the splice operation, the original array no longer contains the elements spliced
out. For example, consider the following code:
@foo = (0..9);
print join(':', @foo), "\n";
0:1:2:3:4:5:6:7:8:9 Now, try it this way:
@foo = (0..9);
splice(@foo, 3, 4);
print join(':', @foo), "\n";
0:1:2:7:8:9
The
splice operation started at element number three and removed four elements. So elements three, four, five, and
six have been removed from the array.The splice function is not used as frequently as the others, but it is good to have an understanding of how it
works.
|
||
|
|
||
