Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
laziness, impatience, and hubris
 
PerlMonks  

Re: checking from a module if a sub exists in main::

by premchai21 (Curate)
on Nov 19, 2001 at 21:55 UTC ( [id://126413]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to checking from a module if a sub exists in main::

A better idea would be to do something like this:
package Foo; use vars qw/$delHook/; $delHook = undef;
Export $delHook if you like. Then, in the main script:
$Foo::delHook = \&somehook; # or just $delHook if exported
will set $delHook; in the module, when you need to call the sub:
$delHook->(any_arguments_here) if defined $delHook;
That way, rather than being restricted to calling a sub with a particular name, you call the subroutine by having a reference to it (which is what the \ does; the & is just to specify that it's the method and not something else). Note that the call will not occur if no delHook was set.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://126413]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.