Check the frequency
#!/usr/bin/perl
use warnings;
use strict;
sub frequency {
my $text = join('', @_);
my %letters;
foreach (split //, $text) {
$letters{$_}++;
}
return %letters;
}
my $text = "this is a test";
my %count = frequency($text);
foreach (sort keys %count) {
print "\t", $count{$_}, " '$_", ($count{$_} == 1)? "'": "'s", "\n";
}
Related examples in the same category