Compile-time Manipulation

Learn how to do compile-time manipulation during code generation.

We'll cover the following...

Unlike code written explicitly as code, code generated through string eval gets compiled while our program is running. Where we might expect a normal function to be available throughout the lifetime of our program, a generated function might not be available when we expect it.

The BEGIN block

Force Perl to run code—to generate other code—during compilation by wrapping it in a BEGIN block. When the Perl parser encounters a block labeled BEGIN, it parses and compiles the entire block and then runs it (unless it has syntax errors). When the block finishes running, parsing ...