|
||
|
Using an array as a stack
The shift and unshift functions
The
The shift function
shift and unshift functions work just like pop and push.
However, from the other end of the array.
The
shift function takes the element from the bottom of the stack (element 0):
The
unshift puts an element on the bottom at element 0.
These functions aren't normally thought of in terms of a stack (although they certainly do work the same); rather they are commonly
used to pass parameters to subroutines, including the main function of a Perl program. Their use in
that capacity will be covered in detail later in the course.
|
||
|
|
||
