In this example, we consider a very simple Perl program that tests whether or not a variable is defined. This simple program can be found in Figure 3.1.
This program tests the scalar variable $foo to see if it is defined. In this example, the test would evaluate to false, since the defined test occurs before anything has been assigned to $foo.
Figure 3.2 contains the OP-tree of this program. The top-level OP is the ``leave'' LISTOP. This OP is always the final OP evaluated by the PVM, and is the parent of the rest of the program.
The ``enter'' OP simply notes that a program has been entered. The ``nextstate'' OP indicates that the evaluation will continue on to another statement in the program.
The ``defined'' OP is UNOP, or unary operator. This means that ``defined'' takes one argument. That argument is a child OP of ``defined''. That child OP is an SVOP, or scalar operator. The type of the SVOP is ``gvsv'', which means it refers to a global scalar variable. The data attached to the SVOP is what is called a ``typeglob'', an internal perl data structure that is used to refer to a symbol table entry for foo. That symbol table entry can in turn access the scalar entity, $foo.
This example is indeed quite trivial. The next section discusses a slightly more complex example.
Copyright © 2000, 2001 Bradley M. Kuhn.
Verbatim copying and distribution of this entire thesis is permitted in any medium, provided this notice is preserved.