Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Find column number for the row-wise max value

by ikegami (Patriarch)
on Feb 29, 2012 at 18:39 UTC ( [id://956996]=note: print w/replies, xml ) Need Help??


in reply to Find column number for the row-wise max value

Lists all columns that have the highest in the event of a tie (e.g. id004;10;30;30)

use strict; use warnings; use feature qw( say ); use List::Util qw( max ); <>; while (<>) { chomp; my @fields = split /;/; my %indexes; push @{ $indexes{ $fields[$_] } }, $_ for 1..$#fields; say join ",", @{ $indexes{ max keys %indexes } }; }

As a "one liner":

perl -MList::Util=max -F\; -lanE' BEGIN { <> } my %indexes; push @{ $indexes{ $F[$_] } }, $_ for 1..$#F; say join ",", @{ $indexes{ max keys %indexes } }; '

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-03-19 05:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found