I tried to find the error myself, but don't see it. The following code produces warnings (same problem in Perl 5.18.2 and 5.32.1).
Use of uninitialized value in numeric comparison (<=>) at test.pl line 14.
while the comparison function of the sort is performed (and, as a consequence, the sort operation is not performed correctly). As far as I see, no value of the hash is initial, they all have defined numeric values.
use strict;
use warnings;
# Sort the occurrences of letters in a list of words, highest count first.
my @words = ('ACGT','CCGT','CATG'); # Just an example
my $a = join '',@words;
my $l = length $a;
my %count = ();
for (my $i = 0; $i < $l; $i++) {
my $x = substr( $a, $i, 1);
$count{$x}++;
}
for my $x (sort { $count{$b} <=> $count{$a} } keys %count) {
print "$x: $count{$x}\n";
}
Remark : it didn't help adding the hash element creation line before incrementing it with the $count{$x}++; statement - same result (expectedly, as undef counts like 0 for the increment operation):
...
$count{$x} = 0 unless defined $count{$x};
$count{$x}++;
...