diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-05-01 01:06:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-01 01:06:48 +0100 |
| commit | af1088f536ef4a3bd7cf00cf1a4c5521faee60d4 (patch) | |
| tree | e3979ae3e2cf41d680847ac1076638eee4756715 | |
| parent | 81611f270e286e6eb064c88a3fe5ed6a04424cd5 (diff) | |
| parent | 70d76b56ec16de39ae9f76c057faa063c5820994 (diff) | |
| download | perlweeklychallenge-club-af1088f536ef4a3bd7cf00cf1a4c5521faee60d4.tar.gz perlweeklychallenge-club-af1088f536ef4a3bd7cf00cf1a4c5521faee60d4.tar.bz2 perlweeklychallenge-club-af1088f536ef4a3bd7cf00cf1a4c5521faee60d4.zip | |
Merge pull request #3982 from wlmb/challenges
Add solutions to challenge 110
| -rw-r--r-- | challenge-110/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-110/wlmb/perl/ch-1.pl | 10 | ||||
| -rwxr-xr-x | challenge-110/wlmb/perl/ch-2.pl | 11 | ||||
| -rwxr-xr-x | challenge-110/wlmb/perl/ch-2a.pl | 15 |
4 files changed, 37 insertions, 0 deletions
diff --git a/challenge-110/wlmb/blog.txt b/challenge-110/wlmb/blog.txt new file mode 100644 index 0000000000..3764858532 --- /dev/null +++ b/challenge-110/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2021/04/27/PWC110/ diff --git a/challenge-110/wlmb/perl/ch-1.pl b/challenge-110/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..a8b9bca7f1 --- /dev/null +++ b/challenge-110/wlmb/perl/ch-1.pl @@ -0,0 +1,10 @@ +#!/usr/bin/env perl +# Perl weekly challenge 110 +# Task 2: Valid phone numbers +# +# See https://wlmb.github.io/2021/04/27/PWC110/#task-1-valid-phone-numbers +use strict; +use warnings; +use v5.12; +my $pattern= join '|', map {qr(^\s*$_\s*$)} qw(\+\d{2}\s\d{10} \\(\d{2}\\)\s\d{10} \d{4}\s\d{10}); +print "Output:\n", grep {$_=~$pattern} <>; diff --git a/challenge-110/wlmb/perl/ch-2.pl b/challenge-110/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..d9eca28023 --- /dev/null +++ b/challenge-110/wlmb/perl/ch-2.pl @@ -0,0 +1,11 @@ +#!/usr/bin/env perl +# Perl weekly challenge 110 +# Task 2: Transpose file +# +# Simple version +# See https://wlmb.github.io/2021/04/27/PWC110/#task-2-transpose-file +use strict; +use warnings; +use v5.12; +my @input=map {chomp; [split /,/]} <>; +say join "\n", map { my $c=$_; join ",", map {$input[$_][$c]} 0..@input-1} 0..scalar @{$input[0]}-1; diff --git a/challenge-110/wlmb/perl/ch-2a.pl b/challenge-110/wlmb/perl/ch-2a.pl new file mode 100755 index 0000000000..1363368231 --- /dev/null +++ b/challenge-110/wlmb/perl/ch-2a.pl @@ -0,0 +1,15 @@ +#!/usr/bin/env perl +# Perl weekly challenge 110 +# Task 2: Transpose file +# +# CSV version +# See https://wlmb.github.io/2021/04/27/PWC110/#task-2-transpose-file +use strict; +use warnings; +use v5.12; +use List::Util qw(max); +use Text::CSV qw(csv); +my $input=csv(in=>*ARGV); +my $Ncols=max map {scalar @{$input->[$_]}} @$input-1; +my $transposed=[map {my $c=$_; [map {$input->[$_][$c]} 0..@$input-1]} 0..$Ncols-1]; +csv(in=>$transposed, out=>*STDOUT, eol=>$/); |
