X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlmod.pod;h=6f98cf6d990e2d484f4e2e76a579d5c3977e2bfb;hb=22d4bb9ccb8701e68f9243547d7e3a3c55f70908;hp=6bec46b0287ed487a4938cb86248dab10af76846;hpb=4b19af017623bfa3bb72bb164598a517f586e0d3;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlmod.pod b/pod/perlmod.pod index 6bec46b..6f98cf6 100644 --- a/pod/perlmod.pod +++ b/pod/perlmod.pod @@ -8,7 +8,7 @@ perlmod - Perl modules (packages and symbol tables) Perl provides a mechanism for alternative namespaces to protect packages from stomping on each other's variables. In fact, there's -really no such thing as a global variable in Perl . The package +really no such thing as a global variable in Perl. The package statement declares the compilation unit as being in the given namespace. The scope of the package declaration is from the declaration itself through the end of the enclosing block, C, @@ -96,6 +96,12 @@ table lookups at compile time: local *main::foo = *main::bar; local $main::{foo} = $main::{bar}; +(Be sure to note the B difference between the second line above +and C. The former is accessing the hash +C<%main::>, which is the symbol table of package C
. The latter is +simply assigning scalar C<$bar> in package C
to scalar C<$foo> of +the same package.) + You can use this to print out all the variables in a package, for instance. The standard but antiquated F library and the CPAN module Devel::Symdump make use of this. @@ -139,7 +145,7 @@ Another use of symbol tables is for making "constant" scalars. *PI = \3.14159265358979; -Now you cannot alter $PI, which is probably a good thing all in all. +Now you cannot alter C<$PI>, which is probably a good thing all in all. This isn't the same as a constant subroutine, which is subject to optimization at compile-time. A constant subroutine is one prototyped to take no arguments and to return a constant expression. See @@ -304,6 +310,10 @@ create a file called F and start with this template: } our @EXPORT_OK; + # exported package globals go here + our $Var1; + our %Hashit; + # non-exported package globals go here our @more; our $stuff;