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

Re: Sorting non-standard elements

by TedPride (Priest)
on Oct 29, 2004 at 19:39 UTC ( [id://403886]=note: print w/replies, xml ) Need Help??


in reply to Sorting non-standard elements

I'm not exactly sure what you want, but I'm assuming you're looking to sort first by word, then by each of the three numbers. Something like the following might work:
use strict; use warnings; my @arr; while (<DATA>) { chomp; m/(\d+)\.(\d+)\.(\d+)(\w*)/; $arr[$#arr+1] = [$4,$1,$2,$3,$_]; } @arr = sort {@$a[0] cmp @$b[0] or @$a[1] <=> @$b[1] or @$a[2] <=> @$b[ +2] or @$a[3] <=> @$b[3]} @arr; for (@arr) { print @$_[4]."\n"; } __DATA__ 1.2.3YABBA 4.2.7 3.2.1DABBA 9.1.3 4.5.1DOO 12.19.47

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-23 20:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found