On Wed, 28 Aug 2013 12:34:40 -0400 Harry Putnam <rea...@newsguy.com> wrote:
> Good thinking thanks. It might not really apply here though. > I'm no kind of data manager... just a homeboy hillbilly. > > What I had in mind is writing to a single log file that is dated on > the file name for each run of the program. That file will sooner or > later be deleted by another part of the script that will try to leave > 5 of the most recent logs. Try this. It will keep rotating log files for the day-of-month, month, and year. # -------------------------------------- # Name: start_logging # Usage: $log_fh = start_logging( $log_file ); # Purpose: To open log file and set a day-of-month, month, and year # file that tracks it. # Parameters: $log_file -- full path to log file # Returns: $log_fh -- file handle to open log file # use Carp; use English qw( -no_match_vars ); # Avoids regex performance penalty use File::Basename; use POSIX; sub start_logging { my $log_file = shift @_; my @now = localtime; open my $log_fh, '>', $log_file or croak "could not open $log_file because: $OS_ERROR\n"; my $dir = dirname( $log_file ); # link to day-of-month log file my $day_file = strftime "$dir/day_%d.log", @now; unlink $day_file; # ignore errors link $log_file, $day_file or carp "could not link to day-of-month file, $day_file because: $OS_ERROR\n"; # link to month log file my $month_file = strftime "$dir/mo_%m.log", @now; unlink $month_file; # ignore errors link $log_file, $month_file or carp "could not link to day-of-month file, $month_file because: $OS_ERROR\n"; # link to year log file my $year_file = strftime "$dir/yr_%Y.log", @now; unlink $year_file; # ignore errors link $log_file, $year_file or carp "could not link to day-of-month file, $year_file because: $OS_ERROR\n"; return $log_fh; } -- Don't stop where the ink does. Shawn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/