Quick actions

cmd+k|ctrl+k

Navigation

Languages

counting characters in a message sent by a baseball

Snippet info

Language

Perl

Visibility

public

Author

grtodd

Created

2017-03-04T01:14:02Z

Updated

2023-06-06T19:04:27.849959Z

# Here is a program to count the numbers of each character
# show n in the "Input" tab below.  If you click "Run" the 
# pregram will run and show you the answer in the "Output"
# box.

while (<>) {
  foreach my $character (split //) {
    if ($character =~ "\n") {
      $counted{"\\n"}++ ;
      }
    else {
      $counted{$character}++ ;
    }
  }
}

foreach my $character (sort {$counted{$a} <=> $counted{$b}} keys %counted) {
      print "$character \t $counted{$character}\n";
}
INFO