Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: sort based on column values

by ikegami (Patriarch)
on Jun 22, 2009 at 04:37 UTC ( [id://773482]=note: print w/replies, xml ) Need Help??


in reply to sort based on column values

Create an array where each element represents a row as an array of fields.

my @lines; while (<>) { chomp; push @lines, [ $_, split /\t/ ]; } @lines = sort { $a->[9] <=> $b->[9] } @lines; for (@lines) { print "$_->[0]\n"; }

It can be written more tersely as:

print map "$_->[0]\n", sort { $a->[9] <=> $b->[9] } map [ $_, split /\t/ ], map { chomp( my $s = $_; ); $s } <>;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-20 02:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found