Perl Monk, Perl Meditation | |
PerlMonks |
Re: Unusual variable declarationby davido (Cardinal) |
on Nov 02, 2019 at 21:50 UTC ( [id://11108265]=note: print w/replies, xml ) | Need Help?? |
Observe the following:
The output:
This is aliasing; you're creating in main a symbol that refers to the same variable that is known in Foo as $var. Notice they share the same memory address. (It will be a different address on your system). In your example code you were creating $var in the current package and aliasing it to $main::var (the $var that belongs to main::). The example I gave is going in the opposite direction because it's easier to demonstrate. But the concept is the same; you're setting up a symbol that refers to the same thing that is known in another package namespace simultaneously. This is what Exporter does. Dave
In Section
Seekers of Perl Wisdom
|
|