You're close. You just need to use the fully qualified name of the sub you're trying to find. And it wouldn't hurt to build in some error checking to alert you if the sub you're looking for doesn't exist. Here's an example:
package MyTest; use strict; use warnings; sub findsub { my $subref; if( defined &main::testsub ) { $subref = \&main::testsub; } else { die "main::testsub doesn't exist.\n"; } $subref->( "Hello world!\n" ); } 1; package main; MyTest::findsub(); sub testsub { print shift; }
Dave
In reply to Re: reaching into a perl script from a package
by davido
in thread reaching into a perl script from a package
by Brad.Walker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |