aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-04-28 20:58:43 +0200
committerAbigail <abigail@abigail.be>2021-04-28 20:58:43 +0200
commit074bba6efd01209cbffb697a86e6b8304fa8de74 (patch)
tree98cc9945f999091e628d30e85f7a7041479bc831
parent9537159d9b52b45821907079185ff167dfbbcb88 (diff)
downloadperlweeklychallenge-club-074bba6efd01209cbffb697a86e6b8304fa8de74.tar.gz
perlweeklychallenge-club-074bba6efd01209cbffb697a86e6b8304fa8de74.tar.bz2
perlweeklychallenge-club-074bba6efd01209cbffb697a86e6b8304fa8de74.zip
Perl solution for week 110, part 2
-rw-r--r--challenge-110/abigail/README.md1
-rw-r--r--challenge-110/abigail/perl/ch-2.pl34
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-110/abigail/README.md b/challenge-110/abigail/README.md
index 93a73192a7..2aef4e6bdc 100644
--- a/challenge-110/abigail/README.md
+++ b/challenge-110/abigail/README.md
@@ -76,6 +76,7 @@ sex,m,m,f,f
### Solutions
+* [Perl](perl/ch-2.pl)
### Blog
diff --git a/challenge-110/abigail/perl/ch-2.pl b/challenge-110/abigail/perl/ch-2.pl
new file mode 100644
index 0000000000..aef60b4713
--- /dev/null
+++ b/challenge-110/abigail/perl/ch-2.pl
@@ -0,0 +1,34 @@
+#!/opt/perl/bin/perl
+
+use 5.032;
+
+use strict;
+use warnings;
+no warnings 'syntax';
+
+use experimental 'signatures';
+use experimental 'lexical_subs';
+
+#
+# See ../README.md
+#
+
+#
+# Run as: perl ch-2.pl < input-file
+#
+# We make the assumption the input has the same number
+# of fields on each line.
+#
+
+#
+# Read in the data, split into fields, add the fields to a set strings,
+# placed in an array @;. Add commas after each field.
+#
+map {$- = 0; $; [$- ++] .= "$_," for /[^,\n]+/g} <>;
+
+#
+# Remove trailing commas, print lines.
+#
+chop, say for @;
+
+__END__