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 } }; '
|
|---|