At a guess your reference to a subroutine in the current package is a string naming the subroutine, in which case you are doing a symbolic lookup. That breaks when the lookup is done in another package. The simplest way to check that is through use strict, which will catch the error up front rather than through allowing subtle bugs in your code and understanding survive. That said, here is a working example:
Note that I am explicitly creating the reference, as perlref says to, using a \. And it works.package Foo; use strict; # Always sub foo { (shift)->(); # Call the function passed in by reference } package Bar; sub bar { print "This is bar\n"; } Foo::foo(\&bar); # Pass a ref to a sub to another package
In reply to Re (tilly) 1: Question about coderefs
by tilly
in thread Question about coderefs
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |