Hello perlancar,
With warnings enabled, the second code gives me:
17:01 >perl -we "package Foo; sub readpipe { die }; package main; BEGI +N { my $rp = qq[main::readpipe]; *{ $rp } = \&Foo::readpipe; } print +readpipe('ls')" Ambiguous call resolved as CORE::readpipe(), qualify as such or use & +at -e line 1. 1801_SoPW.pl 1802_SoPW.pl 1803_CUfP ...
I don’t understand why the compiler sees the call as ambiguous; but following the advice in the warning and prepending an ampersand to the readpipe function does give the desired result:
17:01 >perl -we "package Foo; sub readpipe { die }; package main; BEGI +N { my $rp = qq[main::readpipe]; *{ $rp } = \&Foo::readpipe; } print +&readpipe('ls')" Died at -e line 1. 17:04 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Overriding built-in function works only via import()?
by Athanasius
in thread Overriding built-in function works only via import()?
by perlancar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |