The difference between use and require is that use calls the module at the compile time and all names inside of the module became available in the rest of the script, and you do not need to qualify the names with the package/module name. Require only calls the package at the run time. I suggest that beginners using modules choose use instead of require to simplify their coding and avoid confusion. It is OK to require a subroutine, like cgi-lib.pl, for you will be able to use the names inside the subroutine without reference to a package name (remember subroutines are not packages/modules), like in &MethGet.
In order to use the names (functions, variables, filehandlers) inside of a module you need to know their names and what they are and do, see Example 13a for a script using the Rest.pm module we saw previously. Many modules automatically export names to your script, but with some modules and names you may need to make explicit the names you want to be able to use them. The format to call the module in this case is: use Modulename qw(name1 name2 .. namei);
Perl locates modules by searching the @INC array, which contains a list of library directories. In Windows it refers to files in Perl\lib, while in Linux it will be in /usr/lib/perl5.
In this course I will not teach you how to create classes, but rather how to use them, given our course objectives. You will think of a class as a package/module that provides methods to deal with objects, including their creation.
There are two ways methods are invoked: (a) method class or instance name list as in: $c = find People "Joe"; where find is the method, People is the class/package and Joe is the name list. This method can be confusing sometimes and a second syntax using the -> notation is suggested to beginners and seasoned Perl programmers alike. This second syntax is: class or instance -> method(name list) as in $c = People->find("Joe"); See example16a for a script using the -> notation to use the Person.pm class.
This page is maintained by Al Bento who can be reached at abento@ubmail.ubalt.edu. This page was last updated on October 7, 2002. Although we will attempt to keep this information accurate, we can not guarantee the accuracy of the information provided.