in reply to Hook::LexWrap and core functions

Overriding Built-in Functions

First make sure you can override it

>perl -wle"print( prototype( 'CORE::chomp' ) )" Use of uninitialized value in print at -e line 1. <- Can't >perl -wle"print( prototype( 'CORE::push' ) )" \@@ <- Can

Then go ahead and do it:

BEGIN { *CORE::GLOBAL::push = sub(\@@) { my $array = shift(@_); print("Pushing\n"); return CORE::push(@$array, @_); }; }

Replies are listed 'Best First'.
Re^2: Hook::LexWrap and core functions
by Alien (Monk) on Sep 19, 2008 at 22:43 UTC
    Thank you for your reply ! But,is it possible to wrap it using Hook::LexWrap ? I get a "Can't wrap non-existent subroutine CORE::push"

      Nope, and the error accurately describes the reason you can't. push is not a sub, so you can't get its address, so it can't be wrapped.

      You might be able to wrap *CORE::GLOBAL::push once you create it.

        You were right. After creating CORE::GLOBAL::push , I was able to wrap it . Thanks for your help !
Re^2: Hook::LexWrap and core functions
by blazar (Canon) on Sep 21, 2008 at 10:58 UTC

    Now that I think of it, prototypes are already somewhat deprecated, and of course we're "all" (well, I for one, and I bet most too, but I'm sure someone will disagree instead...) waiting for Perl 6 and its multi's with real signatures, OTOH it would be nice and IMHO not terribly sci-fi-like if prototypes allowed alternation (which I sort of consistently, I hope, represent hereafter with a pipe | character) so that e.g. chomp could have a prototype of:

    @|_
    --
    If you can't understand the incipit, then please check the IPB Campaign.