How can I refer to `sin`?

I can define a subroutine and take a link to it like this

sub F { q(F here) } $f = \&F; print &$f # prints "F here" 

But how can I do the same with, for example, sin ?

 $f = \&sin; print &$f # error: Undefined subroutine &main::sin called 

It sounds like I can use \&MODULE::sin ; obviously cos not in main , but in which module is it in? I do not see documented anywhere.

+5
source share
1 answer

sin not included in your current package. You need to call from the CORE:: namespace . CORE:: is the place where all the built-in functions are located. It is imported automatically.

 my $f= \&CORE::sin; print $f->(1); 

Output:

 0.841470984807897 

Knowing CORE::foo is mostly useful if you want to call the original inline file after the function is reloaded.

 use Time::HiRes 'time'; say time; say CORE::time; 

It is output:

 1442913293.20158 1442913293 
+9
source

Source: https://habr.com/ru/post/1232008/


All Articles