Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Question on alpanumeric sorting

by sridhar8183 (Initiate)
on Aug 31, 2015 at 14:10 UTC ( [id://1140536]=perlquestion: print w/replies, xml ) Need Help??

sridhar8183 has asked for the wisdom of the Perl Monks concerning the following question:

how can i sort a the below array.
("MAINUI_PF_4.0.001.8Q.7769","MAINUI_PF_4.0.001.10BA.8669","MAINUI_PF_ +4.0.001.10AV.7890","MAINUI_PF_4.0.001.10AU.1898")
Expected result:
MAINUI_PF_4.0.001.10BA.8669 MAINUI_PF_4.0.001.10AU.1898 MAINUI_PF_4.0.001.10AV.7890 MAINUI_PF_4.0.001.8Q.7769

Replies are listed 'Best First'.
Re: Question on alpanumeric sorting
by Laurent_R (Canon) on Aug 31, 2015 at 14:28 UTC
    Hi,

    So you apparently want this order:

    MAINUI_PF_4.0.001.10BA.8669 MAINUI_PF_4.0.001.10AU.1898 MAINUI_PF_4.0.001.10AV.7890 MAINUI_PF_4.0.001.8Q.7769
    Or, given that the line start is always the same, basically, you want this order:
    10BA.8669 10AU.1898 10AV.7890 8Q.7769
    You obviously are not sorting on the last field, so that the sort key presumably boils down to:
    10BA 10AU 10AV 8Q

    But even with this simplified view of your data to be sorted, I am at trouble figuring out the sorting rules that can lead to such an order.

    Can you please explain your sorting rules?

Re: Question on alpanumeric sorting
by moritz (Cardinal) on Aug 31, 2015 at 14:14 UTC
Re: Question on alpanumeric sorting
by toolic (Bishop) on Aug 31, 2015 at 14:12 UTC
Re: Question on alpanumeric sorting
by Anonymous Monk on Aug 31, 2015 at 16:18 UTC
    In reading the documentation on "perldoc -f sort," especially notice the discussion of sort-comparison functions and the comparison operators (both string and numeric) that can be used within them.

Log In?
Username:
Password:

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

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

    No recent polls found