Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: sorting numerically and alphabetically

by cLive ;-) (Prior)
on Jun 28, 2006 at 18:26 UTC ( [id://558104]=note: print w/replies, xml ) Need Help??


in reply to sorting numerically and alphabetically

Break up the elements and sort on the two fragments:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper 'Dumper'; my @files = qw(firstcase_1 firstcase_2 firstcase_10 secondcase_4 secon +dcase_1 secondcase_11); my @sorted = sort { $a =~ /^(\w+)_(\d+)$/; my ($a1,$a2) = ($1,$2); $b =~ /^(\w+)_(\d+)$/; my ($b1,$b2) = ($1,$2); $a1 cmp $b1 || $a2 <=> $b2 } @files; print Dumper(\@sorted);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-16 21:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found