The concept of Perl global variables is pretty similar to special variables in CL.
You can obscure the value of a global variable with local :
our $var = 1; func("before"); {
Output:
before: 1 inside: 2 after: 1
If you are a local value, the new value is displayed in the entire dynamic region, that is, in all called functions. The old value is restored after the lexical region remains in any way (errors, returns, etc.). The tail of calls does not expand the dynamic region, but is calculated as the output of the region.
Note that global variables have a fully qualified name. From another package, you would do something like
local $Other::Package::var = 3; Other::Package::func("from a package far, far away");
This is commonly used to provide configuration of packages with a functional (non-OO) interface. Important examples are Carp as well as Data::Dumper .
amon
source share