I'm assuming these are log files to which data is appended based on local time.
If so, forget the file name. It would makes more sense to move all but the newest file based on their modification time.
Hum, on second thought, this might be a bit more accurate:my @log_files = ...[ read list of files from dir ]...; if (@log_files) { my $newest_idx = 0; my $newest_mtime = -M $log_files[0]; for my $idx (1..$#log_files) { my $mtime = -M $log_files[$idx]; next if $mtime < $newest_mtime; $newest_idx = $idx; $newest_mtime = $mtime; } # Leave newest alone. splice(@log_files, $newest_idx, 1, ()); } for my $log_file (@log_files) { ...[ process $log_file ]... }
my @log_files = ...[ read list of files from dir ]...; if (@log_files) { my $newest_idx = 0; my $newest_name = $log_files[0]; for my $idx (1..$#log_files) { my $name = $log_files[$idx]; next if $name lt $newest_name; $newest_idx = $idx; $newest_name = $name; } # Leave newest alone. splice(@log_files, $newest_idx, 1, ()); } for my $log_file (@log_files) { ...[ process $log_file ]... }
In reply to Re: date issues
by ikegami
in thread date issues
by prborg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |