I want to do two things:
In production code, I want to redefine the open command to enable me to add automagic file logging. I work on data processing applications/f
For open: This worked for me.
use 5.010;
use strict;
use warnings;
use subs 'open';
use Symbol qw;
sub open (*$;@) {
say "Opening $_[-1]";
my ( $symb_arg ) = @_;
my $symb;
if ( defined $symb_arg ) {
no strict;
my $caller = caller();
$symb = \*{$symb_arg};
}
else {
$_[0] = geniosym;
}
given ( scalar @_ ) {
when ( 2 ) { return CORE::open( $symb // $_[0], $_[1] ); }
when ( 3 ) { return CORE::open( $symb // $_[0], $_[1], $_[2] ); }
}
return $symb;
}
open PERL4_FH, '<', 'D:\temp\TMP24FB.sql';
open my $lex_fh, '<', 'D:\temp\TMP24FB.sql';
For Printf: Did you check out this question? -> How can I hook into Perl’s print?