Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Copy a builtin sub to a different name and then override ( goto &SUB )

by LanX (Saint)
on Jun 04, 2018 at 11:55 UTC ( [id://1215820]=note: print w/replies, xml ) Need Help??


in reply to Re: Copy a builtin sub to a different name and then override
in thread Copy a builtin sub to a different name and then override

Hi Beech,

> # goto &CORE::hex; ## FAIL

I can't reproduce any problems with goto &SUB here.

Neither with hex nor with sleep .

How does it "fail" for you?

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

update

use strict; use warnings; warn "Version $]"; warn "Prototype", prototype "CORE::sleep"; my $sleepcounter; BEGIN { *CORE::GLOBAL::sleep = sub { warn "start wrapper ($_[0])"; $sleepcounter += int $_[0]; goto &CORE::sleep; }; } warn "return: ", sleep 2.3; warn "total sleep( $sleepcounter )";
Version 5.016003 at d:/Users/lanx/pm/core_sleep.pl line 4. Prototype;$ at d:/Users/lanx/pm/core_sleep.pl line 5. start wrapper (2.3) at d:/Users/lanx/pm/core_sleep.pl line 15. return: 2 at d:/Users/lanx/pm/core_sleep.pl line 23. total sleep( 2 ) at d:/Users/lanx/pm/core_sleep.pl line 25.

Replies are listed 'Best First'.
Re^3: Copy a builtin sub to a different name and then override ( goto &SUB )
by beech (Parson) on Jun 07, 2018 at 22:13 UTC

    # goto &CORE::hex; ## FAIL This works for me under 5.016003 even without the correct prototype:

    Hi,

    It turns out it works as designed, it merely returns different from CORE::hex(@_) , because of the prototype . I only checked for prototype on "hex" because it worked on "sleep", I forgot I preload Time::HiRes, I should have checked CORE::hex

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1215820]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-26 03:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found