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]
- Re: code ref and objects todd shifflett
- Re: code ref and objects Wiggins d'Anconia
- Re: code ref and objects Jason Tiller
- Re: code ref and objects debraj bhattacharyya
- push'ing items onto an array David Buddrige
- RE: push'ing items onto an array Beau E. Cox
- Re: push'ing items onto an array Paul Johnson
- Re: push'ing items onto an array David Buddrige
- Fwd: code ref and objects todd shifflett
- Re: Fwd: code ref and objects Jason Tiller