go ahead... be a heretic | |
PerlMonks |
Re: Packages and Modulesby ELISHEVA (Prior) |
on Mar 06, 2011 at 13:18 UTC ( [id://891680]=note: print w/replies, xml ) | Need Help?? |
use doesn't assign your script of module file to a package. It simply makes the functions in another package available to your own code. If you think about it, use can't be defining your module's package because you can have lots of use statements at the top of your file (by the way those highlighted terms are links to the formal Perl documentation - click on them and you will see the actual definition of "use"). Which one would be the package? The phrase "a package says in effect until..." is referring to this statement that you often find in the top of code files: package Foo::Bar::MyFrobinicator;What that statement does is declare a namespace. All of the our variables and subroutines that you define after the package Foo::Bar::MyFrobnicator statement belong to the "Foo::Bar::MyFrobnicator" package. So if you define a sub called "make_frobnicator", then its fullly qualified name will be "Foo::Bar::MyFrobnicator::make_frobnicator". Of course, that is a lot of typing, so Perl gives you a shortcut. As long as the "Foo::Bar::MyFrobnicator" namespace is effect, you can just type "make_frobincator" and Perl will figure out that what you meant was "Foo::Bar::MyFrobnicator::make_frobnicator". (Perl is nice to people who don't like to type). This namespace and all the benefits it gives stays in effect until your code includes another package statement, lets say package Foo::Baz, like this:
In Section
Seekers of Perl Wisdom
|
|