[Appendix D] D.9 Packages
Author: Randal L. Schwartz, Erik Olson & Tom Christiansen
Date: 1999-07-02T01:38:25Z

#

| Appendix D Topics We Didn't Mention |

## D.9 Packages

When multiple people work on a project, or if you're slighly schizophrenic, you can carve up the variable namespace using packages. A package is just a hidden prefix put in front of most variables (except variables created with the `my` operator). By changing the prefix, you get different variables. Here's a brief example:

    $a = 123;            # this is really $main::a
    $main::a++;          # same variable, now 124
    package fred;        # now the prefix is "fred"
    $a = 456;            # this is $fred::a
    print $a - $main::a; # prints 456-124
    package main;        # back to original default
    print $a + $fred::a; # prints 124+456

So, any name with an explicit package name is used as is, but all other names get packaged into the current default package. Packages are local to the current file or block, and you always start out in package `main` at the top of a file. For details, the perlsub documentation will help here.

D.8 Additional Regular Expression Features |  | D.10 Embeddible, Extensible