I'd rewrite the sub as:
sub files_sort { my $re = qr/(\d+)_\d+_duration_\w+_comptage_\d+.txt$/; my $first_number = $a =~ $re ? $1 : -1; my $second_number = $b =~ $re ? $1 : -1; return $first_number <=> $second_number; }
which is slightly more compact and deals better with bad matches by avoiding comparing undefined values. Explicit returns are good too.
In reply to Re^2: sorting files
by GrandFather
in thread sorting files
by steph_bow
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |