Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: How to sort in perl on the basis of one field.

by 2teez (Vicar)
on Jul 29, 2014 at 07:07 UTC ( [id://1095469]=note: print w/replies, xml ) Need Help??


in reply to How to sort in perl on the basis of one field.

Hi Aukur kuls,
If I may add my voice to that of others, that what you seek can be done in a single "breath" with what is called popularly known as Schwartzian Transform.
Using a modified version of what you posted one can do:

use warnings; use strict; print map { $_->[0] } sort { $b->[1] <=> $a->[1] } map { [ $_, ( split /[,\s\D]+/, $_ )[2] ] } <DATA>; __DATA__ field15,field78,filed0 field90,field12,filed23 field3,field55,filed67

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-18 00:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found