From 821c027f0105a271d1340561ea4983b0442f7787 Mon Sep 17 00:00:00 2001 From: Niels van Dijke Date: Wed, 28 Apr 2021 13:18:55 +0000 Subject: Added a minimalistic solution for Task 2 based on solutions provided by others their '[split/,/]' usage. --- challenge-110/perlboy1967/perl/ch-2a.pl | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 challenge-110/perlboy1967/perl/ch-2a.pl diff --git a/challenge-110/perlboy1967/perl/ch-2a.pl b/challenge-110/perlboy1967/perl/ch-2a.pl new file mode 100755 index 0000000000..46c1a8302d --- /dev/null +++ b/challenge-110/perlboy1967/perl/ch-2a.pl @@ -0,0 +1,43 @@ +#!/usr/bin/perl + +# Perl Weekly Challenge - 110 +# - https://perlweeklychallenge.org/blog/perl-weekly-challenge-110/#TASK2 +# +# Task 2 - Transpose File +# +# Author: Niels 'PerlBoy' van Dijke +# +# *** Extra submission *** +# Inspired by other solutions usage of '[split/,/]' +# to find minimalistic 'sub transposeFile($)' +# + +use v5.16; +use strict; +use warnings; + +use File::Basename qw(dirname); +use File::Slurp; +use Array::Transpose; + +use Test::More; +use Test::Deep; + +# Prototype(s) +sub transposeFile($); + +# Work relative from script directory +chdir(dirname($0)); + +cmp_deeply ([transposeFile('input2.txt')], + ['name,Mohammad,Joe,Julie,Cristina', + 'age,45,20,35,10', + 'sex,m,m,f,f']); + +done_testing; + + +sub transposeFile($) { + map{join(',',@$_)}transpose[map{s/^\s*(.*?)\s*$/$1/;[split/,/]}read_file($_[0])]; +} + -- cgit