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

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

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


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
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-04-23 10:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found