perl - Is there a way to be notified when 'print' is called on $fh? -


when do:

print $fh 'text'; 

i need &sub called.

it there way that?

you can tie filehandle , customize behavior printing filehandle or other operation on filehandle.

sub printnotifier::tiehandle {     ($pkg, $orignalhandle) = @_;     bless { glob => $orignalhandle }, $pkg; } sub printnotifier::print {     ($self,@msg) = @_;     ... whatever want @msg here ...     return print {$self->{glob}} @msg; } sub printnotifier::close { return close $_[0]->{glob} }  open $fh, '>', 'some-file'; tie *$fh, 'printnotifier', $fh; print $fh "something";           # calls  printnotifier::print 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -