This is a guess but I think you can't 'my' the fft variable and then use it as a reference. Because it is looking for main:: which your my'd variable will not be in that namespace, or any namespace for that matter. If you are working under use strict trying our'ing it instead, or just removing the my without use strict. this is just a guess...... I defer to the other gurus....

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]

Reply via email to