diff options
| -rwxr-xr-x | challenge-110/e-choroba/perl5/ch-1.pl | 29 | ||||
| -rwxr-xr-x | challenge-110/e-choroba/perl5/ch-2.pl | 39 |
2 files changed, 68 insertions, 0 deletions
diff --git a/challenge-110/e-choroba/perl5/ch-1.pl b/challenge-110/e-choroba/perl5/ch-1.pl new file mode 100755 index 0000000000..6a36f86903 --- /dev/null +++ b/challenge-110/e-choroba/perl5/ch-1.pl @@ -0,0 +1,29 @@ +#!/usr/bin/perl +use warnings; +use strict; + +my $VALID = qr/^\s* (?: \([0-9]{2}\) + | \+[0-9]{2} + | [0-9]{4} + ) \s+ + [0-9]{10} $/x; + +sub valid_phone_numbers { + my @valid = grep /$VALID/, @_; + chomp @valid; + return \@valid +} + +use Test::More tests => 1; + +is_deeply valid_phone_numbers(<DATA>), + ['0044 1148820341', + ' +44 1148820341', + '(44) 1148820341']; + +__DATA__ +0044 1148820341 + +44 1148820341 + 44-11-4882-0341 +(44) 1148820341 + 00 1148820341 diff --git a/challenge-110/e-choroba/perl5/ch-2.pl b/challenge-110/e-choroba/perl5/ch-2.pl new file mode 100755 index 0000000000..08bdf011aa --- /dev/null +++ b/challenge-110/e-choroba/perl5/ch-2.pl @@ -0,0 +1,39 @@ +#!/usr/bin/perl +use warnings; +use strict; +use feature qw{ say }; + +sub transpose_file { + my ($input, $output) = @_; + open my $in, '<', $input or die $!; + open my $out, '>', $output or die $!; + + my $maybe_comma = ""; + my @tr; + while (<$in>) { + chomp; + my @cells = split /,/; + $tr[$_] .= "$maybe_comma$cells[$_]" for 0 .. $#cells; + $maybe_comma = ','; + } + say {$out} $_ for @tr; +} + +use Test::More tests => 1; + +my $file = << '__INPUT__'; +name,age,sex +Mohammad,45,m +Joe,20,m +Julie,35,f +Cristina,10,f +__INPUT__ + +my $expected = << '__EXPECTED__'; +name,Mohammad,Joe,Julie,Cristina +age,45,20,35,10 +sex,m,m,f,f +__EXPECTED__ + +transpose_file(\$file, \ my $outfile); +is $outfile, $expected; |
