I can define a subroutine and take a reference to it like this
sub F { q(F here) }
$f = \&F;
print &$f # prints “F here”
But how can I do the same with, e.g., sin
?
$f = \&sin;
print &$f # error: Undefined subroutine &main::sin called
That sounds as though I should be able to use \&MODULE::sin
;
evidently cos
is not in main
, but which module is it in? I do not see that documented anywhere.
&
whenever possible. You need to use it when taking a reference to a subroutine, likemy $f = \&F
, but you should call that reference with$f->()
– Byers