Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Sorting non-standard elements

by TedPride (Priest)
on Oct 29, 2004 at 19:39 UTC ( #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
Node Status?
node history
Node Type: note [id://403886]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2020-06-01 17:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (6 votes). Check out past polls.

    Notices?