in reply to Re^2: Tallying overall frequency of characters in a set of strings by position
in thread Tallying overall frequency of characters in a set of strings by position

$_[0] is the start position of the match in the string.

  • Comment on Re^3: Tallying overall frequency of characters in a set of strings by position

Replies are listed 'Best First'.
Re^4: Tallying overall frequency of characters in a set of strings by position
by Anonymous Monk on May 11, 2016 at 16:40 UTC

    Ah right, now I understand why it was used. When adding more entries to __DATA__ such as:

    __DATA__ AABBC BAABC AABBD AACBB AACBB AACBA
    It returns the error: Missing argument in printf at line 16, <DATA> line 6. I can't quite figure out how to alter the print statements at the end of the script to accommodate variable a number of entries.

      Oops

      #!/usr/bin/perl # http://perlmonks.org/?node_id=1162755 use strict; use warnings; my %score; chomp(my @array = <DATA>); for my $i (1..@array) { $score{$1}[$-[0]] += 1 / @array while $array[$i - 1] =~ /(.)/g; } printf " " . "%5s " x (keys %score) . "\n", sort keys %score; for my $pos ( 1..length $array[0] ) { printf "%1d" . "%7.2f" x (keys %score) . "\n", $pos, map { $score{$_}[$pos - 1] // 0 } sort keys %score; } __DATA__ AABBC BAABC AABBD AACBB AACBB AACBA