Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^4: Sorting a text file

by ArifS (Beadle)
on Dec 06, 2016 at 17:57 UTC ( [id://1177316]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Sorting a text file
in thread Sorting a text file

This seems to work with digits as shows above, however, I couldn't make it work for the following while sorting with the 2nd word (combination)-
_DATA_ CCCCCC-NF-33 LONDON_JAM_2AAA END-ONE_2TWO DDDDDD-NF_52 VENICE_CCC_1ZZZ WHAT_WHEN-1WHY KKKKK-INF_44 JAMAICA_AAA_3TTT HOW-WHERE_3WHAT AAAAA-INF-32 LONDON_JAM_2AAA END-ONE_2TWO BBBBB-INF-12 JAMAICA_AAA_3TTT WHAT_WHEN-1WHY VVVVV-INF_24 VENICE_CCC_1ZZZ END-ONE_2TWO
Any suggestion?

Replies are listed 'Best First'.
Re^5: Sorting a text file
by tybalt89 (Monsignor) on Dec 06, 2016 at 18:11 UTC

    Suggestion: then sort by the second word

    #!/usr/bin/perl # http://perlmonks.org/?node_id=1177316 use strict; use warnings; print sort { (split ' ', $a)[1] cmp (split ' ', $b)[1] } <DATA>; __DATA__ CCCCCC-NF-33 LONDON_JAM_2AAA END-ONE_2TWO DDDDDD-NF_52 VENICE_CCC_1ZZZ WHAT_WHEN-1WHY KKKKK-INF_44 JAMAICA_AAA_3TTT HOW-WHERE_3WHAT AAAAA-INF-32 LONDON_JAM_2AAA END-ONE_2TWO BBBBB-INF-12 JAMAICA_AAA_3TTT WHAT_WHEN-1WHY VVVVV-INF_24 VENICE_CCC_1ZZZ END-ONE_2TWO
      This is a good solution. Thanks

Log In?
Username:
Password:

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

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

    No recent polls found