The only difference between a package and a module is the extension of .pm and and the module requires the package name? Is that right?Uhm, no. A package is a name space, while a module is a file. A module could contain several packages (or part of packages), while a package may be defined in more than one file. It's common to have one package per module, and one file per package, but it's certainly not rare to have more than one package in a file.
From man perlmod:
Packages 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 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, "eval", or file, whichever comes first (the same scope as the my() and local() opera tors). ... Perl Modules A module is just a set of related functions in a library file, i.e., a Perl package with the same name as the file. It is specifically designed to be reusable by other mod ules or programs. It may do this by providing a mechanism for exporting some of its symbols into the symbol table of any package using it, or it may function as a class defi nition and make its semantics available implicitly through method calls on the class and its objects, without explic itly exporting anything. Or it can do a little of both.
Now comes down to the theory behind using modules.. I know there is a difference between use and require, but when it comes to using variables inside the module should we be using $_ or @_ more often than predefined names? Or how does our data imported from our script into the module if it requires specific names? (note: I know some modules have their own variables to use).Huh? I don't understand the reasoning about this question. You don't program in another language if you write a module. It's still Perl, you just use an extra file, and probably a different package than "main". You'd use $_ and @_ in the same way as you would do if you wrote your code in the same file.
You may want to read some manual pages.
Abigail
In reply to Re: Creating modules
by Abigail-II
in thread Creating modules
by sulfericacid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |