Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Override the open builtin globally.. redux

by Anonymous Monk
on Feb 26, 2013 at 20:18 UTC ( #1020751=note: print w/replies, xml ) Need Help??


in reply to Override the open builtin globally.. redux

See: http://www.perl.com/pub/2002/06/11/threads.html?page=2 (at the end) The key is the handling of the undefined case.
*CORE::GLOBAL::open = sub(*;$@) { # push @OpenCalls, [ @_[1..$#_] ]; if (defined($_[0])) { use Symbol (); my $handle = Symbol::qualify($_[0],(caller)[0]); no strict 'refs'; if(@_ == 1) { return CORE::open($handle); } elsif(@_ == 2) { return CORE::open($handle, $_[1]); } else { return CORE::open($handle, $_[1], @_[2..$#_]); } } else { if(@_ == 1) { return CORE::open($_[0]); } elsif(@_ == 2) { return CORE::open($_[0], $_[1]); } else { return CORE::open($_[0], $_[1], @_[2..$#_]); } } };