Put a DESTROY method in your Log class that writes out the line that you want when the log object is destroyed. Leave the IO::File class alone.
use IO::File; package Log; sub new { my ($class, $file) = @_; my $self = bless {}, $class; $self{fh} = IO::File->new( $file, ">>" ) or die $!; return $self; } sub log { my $self = shift; $self{fh}->print( map { scalar localtime() . " $_\n" } @_ ); } sub DESTROY { my $self = shift; $self{fh}->print scalar localtime(), "Finished\n"; $self{fh}->close; }
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
In reply to Re: Redefine DESTROY in class instance
by xdg
in thread Redefine DESTROY in class instance
by tmaly
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |