postman has asked for the wisdom of the Perl Monks concerning the following question:
sub new { my $class_name = shift; my $self = {}; $output_file = shift; $append = shift; $file_handle = undef ; bless ($self,$class_name); bless ($self); return $self; } # opens log file for writing # (no argument) will be called from first call to &message if not call +ed from outside sub start{ my $now = &get_timestamp; print "opening $output_file\n"; if (uc($append)eq'APPEND') { open ($file_handle,">>$output_file") || open ($file_handle,"> +$output_file") || die "Can't open $output_file $!"; }else{ open ($file_handle,">$output_file") || die "Can't open $output +_file $!"; } print $file_handle "Started logging at $now\n"; print $file_handle "Logging to $output_file\n"; print $file_handle "\n"; } #log a message # argument <a status>, <a text message> sub message{ #run start subprocedure if file not already open &start if (!$file_handle); my $status = $_[1]; my $text = $_[2]; print $file_handle "$status : $text\n" ; #$message_number++; } #close log # (no argument) sub finish{ #run start subprocedure if file not already open if (!$file_handle){ &start; }else{ my $now = &get_timestamp; print $file_handle "\n"; print $file_handle "Finished logging at $now\n"; print $file_handle "-------------------------------------\n"; #close ($file_handle); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: creating 2 file writing objects
by vladb (Vicar) on Jun 27, 2002 at 13:54 UTC | |
by bronto (Priest) on Jun 27, 2002 at 14:21 UTC | |
|
Re: creating 2 file writing objects
by Joost (Canon) on Jun 27, 2002 at 14:02 UTC | |
by postman (Acolyte) on Jun 27, 2002 at 15:27 UTC | |
by postman (Acolyte) on Jun 27, 2002 at 20:01 UTC |