[Wellington-pm] Accessing functions in modules

Matthew Hunt matt at catalyst.net.nz
Wed Nov 1 16:12:13 PST 2006


On Thu, 2006-11-02 at 12:48 +1300, Lesley Walker wrote:
> I'm sure this is covered by something in `man perlmod`, but doing that
> makes my brain hurt and I don't have time to teach myself how to
> understand it.
> 
> I'm writing a script to do some SNMP stuff, and I'm using Net::SNMP,
> which contains (among other things I'm also using) a function
> oid_lex_sort().
> 
> What do I have to do so that I can call it by oid_lex_sort() or
> &oid_lex_sort() rather than the more cumbersome
> Net::SNMP::oid_lex_sort()?
> 
> My use statement is just "use Net::SNMP" if that matters.

It does, kindof (there's other ways to import the functions after you've
done "use" without doing so, but I'm not going to go into them).  One
way of importing just that funciton to your namespace is:

 use Net::SNMP qw(&oid_lex_sort);

Look for EXPORTS in the pod for the module and you'll see what else you
could have imported.  That function could also be imported by:

 use Net::SNMP qw(:snmp);

or, of course:

 use Net::SNMP qw(:ALL);

Matt.
-- 
Matthew Hunt
Catalyst IT Limited, PO Box 11053, Wellington   6142
Phone: +64 (4) 499 2267, Direct: +64 (4) 803 2216, Fax: +64 (4) 499 5596
http://catalyst.net.nz/



More information about the Wellington-pm mailing list