http://danconia.org
todd shifflett wrote:
I am trying to use a code reference from within a function to recursively call a given separate function...
#--- LIKE THIS --vv
sub hello {
my $name = shift;
return "Hello, $name!\n";
}
sub foo {
my($f, @args) = @_;
return &$f(@args);
}
print foo(\&hello, "world");
#---^^
the above works. Now I would like to be able to pass in a subroutine from a declared object.
#---- This does not work --vv
use Math::FFT;
my @nums = qw(3 4 5 7 10 8 7 9);
my $fft = new Math::FFT(\@nums);
# this is fine
my $stdev = $fft->stdev(\@nums);
# this is not... ERROR: Undefined subroutine &main::fft->stdev called at ...
print foo(\&{'fft->stdev'},\@nums);
#---^^
So how do I pass in the subroutine for a given object into my function to be called later?
-todd
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]