185

Packages & Modules
The Package Statement

  • The package statement switches the current naming context to a specified namespace (symbol table)

  • If the named package does not exists, a new namespace is first created

      $i = 1; print "$i\n"; # Prints "1"
      package foo;
      $i = 2; print "$i\n"; # Prints "2"
      package main;
      print "$i\n"; # Prints "1"

  • The package stays in effect until either another package statement is invoked, or until the end of the end of the current block or file