aboutsummaryrefslogtreecommitdiff
path: root/challenge-110/abigail/lua/ch-2.lua
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-05-01 01:10:18 +0100
committerGitHub <noreply@github.com>2021-05-01 01:10:18 +0100
commitc86d7cc3cf9f5b4c51d2e6fd99384729a8166418 (patch)
treea8b099562494a78a1aa82ed74c73a40205603a0c /challenge-110/abigail/lua/ch-2.lua
parent111ea37f028e65705520d21e13dcb2735a33ad8a (diff)
parent8bcf6551730487cf51398a844b726d6fed93f647 (diff)
downloadperlweeklychallenge-club-c86d7cc3cf9f5b4c51d2e6fd99384729a8166418.tar.gz
perlweeklychallenge-club-c86d7cc3cf9f5b4c51d2e6fd99384729a8166418.tar.bz2
perlweeklychallenge-club-c86d7cc3cf9f5b4c51d2e6fd99384729a8166418.zip
Merge pull request #3983 from Abigail/abigail/week-110
Abigail/week 110
Diffstat (limited to 'challenge-110/abigail/lua/ch-2.lua')
-rw-r--r--challenge-110/abigail/lua/ch-2.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-110/abigail/lua/ch-2.lua b/challenge-110/abigail/lua/ch-2.lua
new file mode 100644
index 0000000000..627fb8176a
--- /dev/null
+++ b/challenge-110/abigail/lua/ch-2.lua
@@ -0,0 +1,32 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-2.lua < input-file
+--
+
+--
+-- Read in the input, split each line on commas, and create
+-- the ouput strings from the split field.
+--
+local output = {}
+for line in io . lines () do
+ local i = 1
+ for field in line : gmatch ("[^,\n]+")
+ do if output [i] == nil
+ then output [i] = ""
+ end
+ output [i] = output [i] .. field .. ","
+ i = i + 1
+ end
+end
+
+--
+-- Print the output
+--
+for _, line in ipairs (output)
+do print (line : sub (1, -2))
+end