| Jeff 'japhy' Pinyan 2005-07-24, 8:29 pm |
| On Jul 21, Tom Allison said:
> I have two objects.
[snip]
> I have another object in a lib path that looks like:
>
> package HIP;
>
> use strict;
> use warnings;
> use lib '/home/tallison/lib';
> use strict;
> use HIP;
>
> and none of the package functions are visible. I call these methods as
> functions and not as Objects.
Hang on. An "object" is a reference that has been blessed into a specific
package (called, in the OO world, a "class"). A "module" is a Perl source
file ending with ".pm" that typically defines a package.
The HIP module has functions that you're trying to access, right? But
when you call them, you get errors like "function XYZ not defined", right?
This is because they exist in HIP's namespace, not main's (or whatever
package you're calling them from). There are two general solutions here.
The first is to use the functions' full names:
HIP::function_name(...);
instead of just
function_name();
The second is to equip the HIP module with Exporter, which defines a
simple system for exporting symbols (such as functions or variables) to
the package using the module. In this way, you could do:
use HIP qw( function_a $something );
print function_a();
print $something;
which would be identical to:
use HIP (); # import absolutely nothing from HIP
print HIP::function_a();
print $HIP::something;
To find out about Exporter, read its documentation: perldoc Exporter.
>
>
> What is the difference between these two that breaks the second one?
> Why?
>
>
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart
|