Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: How can I import a function and set a parameter at the same time?

by shmem (Chancellor)
on Apr 12, 2009 at 12:15 UTC ( [id://757090]=note: print w/replies, xml ) Need Help??


in reply to How can I import a function and set a parameter at the same time?

For successfully using your notation, the import() routine of the imported module must be aware about and know what to do with the additionally supplied hashref, so, no per default.

My question is, what for? If the function is to be called once after importing, use a BEGIN block after the use MyModule to do so. If MyModule is your module, modify the import() routine so as to call the function immediately with the parameter passed in the hashref, if it's present.

But if you want to set a default parameter for that imported function for every call, you could say:

use MyModule qw(MyFunction); BEGIN { my $subref = \&MyFunction; # already imported *{__PACKAGE__.'::MyFunction'} = sub { $subref->('HelloWord', @_) } +; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 22:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found