Hello Shawn, thank you for answering.

I'm sorry, I was a bit sloppy with my example and so maybe unclear about my 
question ...

It's not about the precise syntax of getting a reference to a subroutine, but 
rather a subroutine in a module.

For example, this pgm is clear:

#!/usr/bin/env perl
sub b { print "hello world\n"; }
my $a = \&b;
&$a;

prints
hello world

But this pgm fails:

#!/usr/bin/env perl
use Math::Trig;
my $a = \&Math::Trig::cos;
&$a(0);

Undefined subroutine &Math::Trig::cos called at modfunctor line 7.


(and other tested variations, too numerous to list here)

e.g.:

my $a = \&cos;
Undefined subroutine &main::cos called at modfunctor line 8.

my $a = "cos";       # symbolic ref
Undefined subroutine &main::cos called at modfunctor line 8.

my $a = "Math::Trig::cos";
Undefined subroutine &Math::Trig::cos called at modfunctor line 9.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to