Skip to content

Instantly share code, notes, and snippets.

@alexws54tk
Created May 27, 2015 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexws54tk/7d5a7a9ac9764b27b684 to your computer and use it in GitHub Desktop.
Save alexws54tk/7d5a7a9ac9764b27b684 to your computer and use it in GitHub Desktop.
Count lelters in entered text
#!/usr/bin/perl -w
use strict;
print "Enter text: ";
my $text = <>;
chomp($text);
my @letters=();
my @chars=split(//,$text);
for my $char (@chars) {
$letters[ord($char)]++;
}
print "Letters in text\n";
for(my $letter=0; $letter <= $#letters+1; $letter++) {
if ($letters[$letter]) {
print "Letter '".chr($letter)."':".$letters[$letter]."\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment