Trevor Vallender wrote:
Hi,

Hello,

I have just moved a piece of code into a separate module. However, the
subroutine in the new module needs to reference a subroutine in the
script it's called from. Is there any way around this?

Basically, I am using AnyEvent::XMPP, and want the setup code in the
module. This code sets up which subroutines to call when certain events
occur, and all these will be in the calling script.

Can I pass the names of subroutines in the calling script to the
subroutine in the module somehow?

No, but you can pass a reference to a subroutine and then dereference it in the module. For example:

$ perl -le'
sub test { print "@_" }
sub in_module {
    my $sub_ref = shift;
    $sub_ref->( "one", 2, "three", 4 );
    }
in_module( \&test );
'
one 2 three 4




John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.               -- Damian Conway

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to