in reply to Tie subroutine to a built-in function call?

Here's an example. You assign a reference to your own subroutine to the CORE::GLOBAL namespace for the function in question within a BEGIN block. In this case, the custom open() will only accept the 3-arg form of open.

use warnings; use strict; BEGIN { *CORE::GLOBAL::open = sub (*;$@) { print "in my open...\n"; # the following line calls the built-in open() function # directly with the params your sub received CORE::open($_[0], $_[1], $_[2]); } }; open my $fh, '<', 'blah' or die $!; print <$fh>;

Output:

in my open... file contents

Replies are listed 'Best First'.
Re^2: Tie subroutine to a built-in function call?
by bcarroll (Pilgrim) on Apr 26, 2017 at 20:22 UTC
    This is exactly what I was looking for!