我如何引用 `sin`?
How do I take a reference to `sin`?
我可以定义一个子程序并像这样引用它
sub F { q(F here) }
$f = \&F;
print &$f # prints “F here”
但是我怎样才能做同样的事情,例如 sin
?
$f = \&sin;
print &$f # error: Undefined subroutine &main::sin called
听起来我应该可以使用 \&MODULE::sin
;
明明 cos
不在 main
里,但它在哪个模块里呢?我没有在任何地方看到该记录。
sin
is not in your current package. You need to call it from the CORE::
namespace。 CORE::
是所有内置函数所在的位置。它是自动导入的。
my $f= \&CORE::sin;
print $f->(1);
输出:
0.841470984807897
如果您想在函数被覆盖后调用原始内置函数,了解 CORE::foo
非常有用。
use Time::HiRes 'time';
say time;
say CORE::time;
这输出:
1442913293.20158
1442913293
我可以定义一个子程序并像这样引用它
sub F { q(F here) }
$f = \&F;
print &$f # prints “F here”
但是我怎样才能做同样的事情,例如 sin
?
$f = \&sin;
print &$f # error: Undefined subroutine &main::sin called
听起来我应该可以使用 \&MODULE::sin
;
明明 cos
不在 main
里,但它在哪个模块里呢?我没有在任何地方看到该记录。
sin
is not in your current package. You need to call it from the CORE::
namespace。 CORE::
是所有内置函数所在的位置。它是自动导入的。
my $f= \&CORE::sin;
print $f->(1);
输出:
0.841470984807897
如果您想在函数被覆盖后调用原始内置函数,了解 CORE::foo
非常有用。
use Time::HiRes 'time';
say time;
say CORE::time;
这输出:
1442913293.20158
1442913293