Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Let a module call a sub of the caller

by SuicideJunkie (Vicar)
on Sep 06, 2012 at 19:11 UTC ( #992167=note: print w/replies, xml ) Need Help??

in reply to Let a module call a sub of the caller

You can pass a reference to a sub, and let other code call that whenever you like...

use strict; use warnings; { my $subref = sub { print "Hey, Hey!\n"; }; Foo($subref); } exit 0; sub Foo { my $callback = shift; print "Foo started\n"; $callback->(); print "Foo is done\n"; }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (12)
As of 2016-10-28 14:21 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (383 votes). Check out past polls.