Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: sorting files

by GrandFather (Saint)
on May 29, 2008 at 20:04 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-24 05:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found