我需要做的是编写一个脚本,它将读取目录列表 ,然后对它们进行排序,最后一个目录将被“关闭”。在ASCII码上按日期对PERL数组进行排序
my $ last_one = pop @sorted;
然后去年目录将会被删除 - 用系统(“RM-RF $ last_one)或 remove_tree($ last_one)
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 my $dir_to_process = "/production/log/fo/archive/";
6 opendir DH, $dir_to_process or die "Sorry, this is not going to work out $!";
7
8 while (my $name = readdir DH) {
9 next if $name =~ /^\./;
10 push(my @unsorted,$name) ;
11 my @sorted_dir = sort @unsorted;
12 foreach my $sorted (@sorted_dir) {
13 print "$sorted\n";
14 sleep 1 ;
15 }
16
17 }
但是我有很多的麻烦分类目录。 - 。它们是由这种格式写 这是实际的输出
2013Nov12
2013Sep14
2013Jul15
2013Jan20
2013Sep11
2013May31
2013Jul04
2012Dec09
2013Oct12
2013Oct09
2012Dec27
2013Nov28
2013Mar24
2013Jun06
2013Jun25
你在标题中说“通过ASCII排序”,但我假设你真正想要的是按日期排序(即最早到最新或反之亦然)? – ThisSuitIsBlackNot
如果你只是想找到最古老的,排序是没有意义的。 – ikegami
问题是,它是按ascii排序,而不是按日期排序 - 是的,我需要的是最古老的日期目录。 – capser