in reply to Count # of occurrences per column
You want to count the number of instances of each character (hash) for each column (array), so you want a AoH.
my @counts; while (<>) { my ($id, @fields) = split; for my $col_num (0..$#fields) { ++$counts[$col_num]{ $fields[$col_num] }; } }
Outputting in the desired format (sorted by descending count) is tricky, though.
for my $col_num (1..$#counts) { # for my $col_num (0, 8) { ?? my $col_counts = $counts[$col_num]; say("column ", $col_num+2); my %by_count; for keys(%$col_counts) { my $count = $col_counts->{$_}; push @{ $by_count{$count} }, $_; } say join ' ', map { join(',', @{ $by_count{$_} }) } keys(%by_count); }
Update: Fixed off-by-one in column number.
|
|---|