我使用此代码过滤文件名,但如果名称包含两位数,则无法正确排序。 如何使代码有意义?
$output_dir
sample1
sample3
sample14
sample9
use strict;
use warnings;
use File::Path qw(remove_tree);
my $path_output = $output_dir;
find1($path_output);
sub find1 {
my ($s) = @_;
my (@dirs) = grep { -d } glob $s . '/*';
my ($link) = sort {
my ($m) = $a =~ m/\/(sample\d+)$/;
my ($n) = $b =~ /\/(rev\d+)$/;
$n cmp $m
}
grep {
/\/sample\d+$/
} @dirs;
foreach ( @dirs ) {
( $_ =~ m/sample(\d+)$/ && $_ ne $link ) ? remove_tree($_) : find1($_);
}
}
sample9
sample13
为什么我的代码中的排序和比较无法使用两位数字?相反,它只考虑0-9。
我想更改我的代码以比较任意数量的数字。我怎么能这样做?