How do I reference print in Perl?

How to link to print

?

I tried:

my $p = \&print;

      

But he throws:

Undefined subroutine &main::print

+3


source to share


1 answer


It will \&CORE::print

, but lists as unavailable . perldoc CORE

print

You can just wrap the anon environment around it and redirect the arguments:

my $p = sub { print @_ };
$p->("hi");

      



Also, the original non-backslash method works in Perl 6 :

my $p = &print; $p("hi")

      

+5


source







All Articles