Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Need help with a script

by lidden (Curate)
on May 27, 2011 at 14:22 UTC ( #906980=note: print w/ replies, xml ) Need Help??


in reply to Need help with a script

You want something like this (untested):

my @sorted = sort {my @A = (split '\|', $a)[4, 5]; my @B = (split '\|', $b)[4, 5]; $A[0] cmp $B[0] || $A[1] <=> $B[1]} @unsorted;

Update: Fixed bug pointed out by chromatic below.


Comment on Re: Need help with a script
Download Code
Re^2: Need help with a script
by chromatic (Archbishop) on May 27, 2011 at 18:02 UTC
    untested

    Trivial bug: splits first operand is a regular expression, not a string, so you need to escape the alternation metacharacter. I used to make that mistake all the time too.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2015-07-05 05:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls