aboutsummaryrefslogtreecommitdiff
path: root/challenge-110/abigail/lua/ch-2.lua
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2021-05-03 18:31:36 +0800
committer冯昶 <fengchang@novel-supertv.com>2021-05-03 18:31:36 +0800
commit81252bda7fb7bcc9e9e153a6b3d268ab8c1a38c8 (patch)
treee4df369a6349802da33aa6d94b7fe745041a9955 /challenge-110/abigail/lua/ch-2.lua
parent0142974e5f11adadbaa7ca8d71de9db345318519 (diff)
parent0381a39b17ccd040302474f25d3c1cbbef703327 (diff)
downloadperlweeklychallenge-club-81252bda7fb7bcc9e9e153a6b3d268ab8c1a38c8.tar.gz
perlweeklychallenge-club-81252bda7fb7bcc9e9e153a6b3d268ab8c1a38c8.tar.bz2
perlweeklychallenge-club-81252bda7fb7bcc9e9e153a6b3d268ab8c1a38c8.zip
Merge remote-tracking branch 'upstream/master'
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