Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: sorting files

by GrandFather (Saint)
on May 29, 2008 at 20:04 UTC ( #689078=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://689078]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2022-12-01 00:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?