Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Sorting a text file

by Anno (Deacon)
on Mar 15, 2007 at 10:47 UTC ( [id://604957]=note: print w/replies, xml ) Need Help??


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

You could turn GrandFather's approach around and swap keys and values in the hash:
my %data; ( $data{ $_}) = /^\d+\s+(\d+)/ while <DATA>; print for sort { $data{ $a} cmp $data{ $b} } keys %data;
This is essentially a variant of the Schwartz Transform, using a hash in place of an array to keep the sort field(s).

Anno

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://604957]
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: (5)
As of 2024-04-18 06:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found