use FileHandle;
our $LOGFH; #can't figure out a way around using a global var here
if ( $opt_s ) {
$LOGFH = new_from_fd FileHandle fileno(STDOUT), 'a';
} else {
$opt_l ||= $DEFAULT_LOG_FILE;
$LOGFH = new FileHandle $opt_l, 'a';
}
( ! defined $LOGFH ) and croak 'Could not open logfile, aborting.';
autoflush $LOGFH 1; #autoflush on
$LOGFH->print(scalar localtime, ": running MyProgram.\n")
or carp 'Could not print to log.';
####
$opt_v and $LOGFH->print("$count records were processed.\n")
or carp 'Could not print to log.';
####
if ( !$opt_s ) {
$LOGFH->print(q{-} x 50, "\n") or carp 'Could not print to log.';
close $LOGFH or croak "Could not close the logfile: $!";
}