Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Using only one subroutine from module file

by ferreira (Chaplain)
on Jun 27, 2007 at 20:01 UTC ( #623726=note: print w/replies, xml ) Need Help??

in reply to Using only one subroutine from module file

First, it is important that you remember the difference between methods (sort of "subs called on an object or class") and subroutines. For methods, you just need to say

require Sheets; Sheets->make_files;
or invoke some kind of constructor (creating an object) and using a piece of code like this:
require Sheets; Sheets->new->make_files;
There is no need for doing more to have access to a method (no need for exporting, etc.)

If the issue is with subroutines, the following may be valid. If you don't want to change or is not under your control, the following may do the trick you want:

# load Sheets require Sheets; # making it known to the current package # alias the function that matters *make_files = \&Sheets::make_files; # use it make_files() # call cleanly Sheets::make_files
(and you can discard the alias as well and use directly as Sheets::make_files, which is not that bad if used in a limited scope).

The suggestion of the paragraph above "works" independent of the exporter module used or the idiosyncrasies of the provided import function. Well, works if there is not too much magic behind the panes.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://623726]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2023-02-08 22:55 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (44 votes). Check out past polls.