Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2016-07-29 00:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?


















    Results (259 votes). Check out past polls.