diff options
| -rwxr-xr-x | challenge-110/stuart-little/perl/ch-1.pl | 32 | ||||
| -rwxr-xr-x | challenge-110/stuart-little/perl/ch-2.pl | 33 |
2 files changed, 65 insertions, 0 deletions
diff --git a/challenge-110/stuart-little/perl/ch-1.pl b/challenge-110/stuart-little/perl/ch-1.pl new file mode 100755 index 0000000000..27d3e71249 --- /dev/null +++ b/challenge-110/stuart-little/perl/ch-1.pl @@ -0,0 +1,32 @@ +#!/usr/bin/perl +use warnings; +use v5.12; + +# run <script> <path-to-file or nothing> +# defaults to text at the bottom if no file is entered + +use feature qw(signatures); +no warnings qw(experimental::signatures); + +sub getNrs($data) { + my @nrs = $data =~ m/((?:\+\d{2}|\(\d{2}\)|\d{4})\s+\d{10})/gsm; + return \@nrs; +} + +my $fh; +(scalar @ARGV) ? (open($fh, '<', $ARGV[0])) : ($fh = *DATA); + +my $data; +{ + local $/ = undef; + $data = <$fh>; +} + +for (@{getNrs($data)}) {say}; + +__DATA__ +0044 1148820341 + +44 1148820341 + 44-11-4882-0341 +(44) 1148820341 + 00 1148820341 diff --git a/challenge-110/stuart-little/perl/ch-2.pl b/challenge-110/stuart-little/perl/ch-2.pl new file mode 100755 index 0000000000..fd459df8de --- /dev/null +++ b/challenge-110/stuart-little/perl/ch-2.pl @@ -0,0 +1,33 @@ +#!/usr/bin/perl +use warnings; +use v5.12; + +# run <script> <path-to-file or nothing> +# defaults to text at the bottom if no file is entered + +use feature qw(signatures); +no warnings qw(experimental::signatures); + +use List::AllUtils qw(zip_by); + +my $fh; +(scalar @ARGV) ? (open($fh, '<', $ARGV[0])) : ($fh = *DATA); + +my @data = (); +while (<$fh>) { + chomp; + my @line = split(/,\s*/,$_); + push @data, \@line; +} + +my @transData = map {join(",",@{$_})} zip_by { [ @_ ] } @data; +for (@transData) { + say; +} + +__DATA__ +name,age,sex +Mohammad,45,m +Joe,20,m +Julie,35,f +Cristina,10,f |
