aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Cross <>2019-10-28 12:11:15 +0000
committerDave Cross <>2019-10-28 12:11:15 +0000
commitfab17ae14261d679e7952889901b16a8b029f8aa (patch)
tree65d16d8fa91853ab2452ea9909504886cfec4343
parent30ca236474bf0bf70dc6f725c450eb5c5db85712 (diff)
downloadperlweeklychallenge-club-fab17ae14261d679e7952889901b16a8b029f8aa.tar.gz
perlweeklychallenge-club-fab17ae14261d679e7952889901b16a8b029f8aa.tar.bz2
perlweeklychallenge-club-fab17ae14261d679e7952889901b16a8b029f8aa.zip
Added challenge #032 / task #1
-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