aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-032/dave-cross/perl5/ch-1.pl22
-rw-r--r--challenge-032/dave-cross/perl5/input6
2 files changed, 28 insertions, 0 deletions
diff --git a/challenge-032/dave-cross/perl5/ch-1.pl b/challenge-032/dave-cross/perl5/ch-1.pl
new file mode 100644
index 0000000000..42a706b7ed
--- /dev/null
+++ b/challenge-032/dave-cross/perl5/ch-1.pl
@@ -0,0 +1,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{$_};
+}
diff --git a/challenge-032/dave-cross/perl5/input b/challenge-032/dave-cross/perl5/input
new file mode 100644
index 0000000000..00fe021a08
--- /dev/null
+++ b/challenge-032/dave-cross/perl5/input
@@ -0,0 +1,6 @@
+apple
+banana
+apple
+cherry
+cherry
+apple