Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: problem sorting by non-consecutive fields

by davido (Cardinal)
on Apr 07, 2004 at 20:40 UTC ( [id://343427]=note: print w/replies, xml ) Need Help??


in reply to problem sorting by non-consecutive fields

One way to do it would be to use a Schwartzian Transform combined with the Logical Short Circuit 'or' operator for sort comparison fall-through.

my @data = ( "7 modify ldfapg pub abc.h", "8 modify bfxml dtd/src newfiles.ksh", "9 delete bfxml dtd/src newfiles.ksh", "10 modify bfxml dtd/src newfiles.ksh" ); my @sorted = map { $_->[0] } sort { $a->[1][2] cmp $b->[1][2] or $a->[1][0] <=> $b->[1][0] } map { [ $_, [ split /\s+/, $_ ] ] } @data;

UPDATE: What do you mean by "using sort +2 +0 -n file the third field should be sort based on the first letter and the first based on the number."??? Are you using Perl and Perl's sort, or are you using your operating system's sort tool?


Dave

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-04-23 13:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found