You can tiehandle it as the crowd suggested. Or, if you can change the code and your Perl is new enough, you can replace
print $fh 'text';
from
$fh->print('text');
which you might consider a cleaner syntax; then you can subclass IO :: File:
package MyFH {
use parent qw/ IO::File /;
use mro;
sub print {
my ($self, @args) = @_;
warn 'Printing ', @args;
$self->next::method(@args);
}
}
my $fh = MyFH->new();
$fh->open('file', '>') or die $!;
However, this does not fix the old-fashioned
print $fh 'text';
style.
, ,
$obj->method()->print('text');
print {$obj->method()} 'text';
Perl 5.14 , Perls ( ) 5.8,
use IO::Handle;
, ( ).