http://qs1969.pair.com?node_id=689078


in reply to Re: sorting files
in thread sorting files

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.


Perl is environmentally friendly - it saves trees