Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How do I do a natural sort on an array?

by tye (Sage)
on Mar 30, 2001 at 01:07 UTC ( [id://68202]=note: print w/replies, xml ) Need Help??


in reply to How do I do a natural sort on an array?

my %data; foreach my $data ( @data ) { ( my $sort= $data ) =~ s/(0*)(\d+)/ pack("C",length($2)) . $1 . $2 /ge; $data{$sort}= $data; } my @sorted= @data{ sort keys %data };
Bugs and features
  • Doesn't properly sort decimal values like 12.34
  • Sorts negative integers in reverse after positive integers
  • Requires more memory than other methods I'll be adding

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (1)
As of 2024-04-25 00:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found