The chop version is wrong, it's trimming chars from the end, but counting them from zero. This fixes that:
for( @data ) { ## use $_ to alias the +lines my $p = length(); ## Allow pre-decrement +and count backwards $freq{ chop() }[ --$p ] += $inc while $p; ## implicit arg for cho +p; avoid call to length. }
In reply to Re^4: Weighted frequency of characters in an array of strings (Bug fix.)
by BrowserUk
in thread Weighted frequency of characters in an array of strings
by K_Edw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |