Whew! We have now finished a reasonably in-depth look at all the value types offered by Perl. The next half of this chapter is devoted to understanding the data structures, API, and protocol used between caller and called subroutines.
We mentioned earlier that the argument stack is the data structure
used for passing parameters and results between functions. Figure 20.11 shows the stack after calling
foo(10,20), which in turn has called
Figure 20-11. Argument and mark stack after foo has been called and foo has just called bar
bar know how many parameters it should
pick up from the top of
stack? Well, Perl keeps
track of the stretches of the argument stack using another stack
(a stack of bookmarks, in a sense).
bar knows the
parameters meant for it by simply computing the difference between
the current top of
stack and the bookmark stored
at the top of
markstack. This stretch of the stack
array. Conversely, when
bar is ready to return, it
dumps one or more results in its stretch of stack, and
foo knows how many scalars have been returned by
looking at the markstack.
All these manipulations happen transparently when you are in script space. But if you write C routines that are called by Perl (extending Perl) or call Perl functions from C (embedding Perl), there are some details ...