aboutsummaryrefslogtreecommitdiff
path: root/challenge-032/dave-cross/perl5/ch-1.pl
blob: 42a706b7ed760d46291590ae7153388a93a2a848 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/perl

use strict;
use warnings;
use feature 'say';

my $csv;
if ($ARGV[0] eq '-csv') {
  shift;
  $csv = 1;
}

my %count;

while (<>) {
  chomp;
  $count{$_}++;
}

for (sort { $count{$b} <=> $count{$a} } keys %count) {
  say $_, ($csv ? ',' : "\t"), $count{$_};
}