diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-04-26 17:07:44 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-26 17:07:44 +0100 |
| commit | 11af07e28eacf5bfec1ee542c1dbd7b8d1e71291 (patch) | |
| tree | 45d7ae5fa3a0eb5aa82e2956bfa60b9821c6f4c6 | |
| parent | 8a38d56f1e8689a73a8c486a590a1a55b26c0dd1 (diff) | |
| parent | 34595087f49d6292a09dfa9452efe1e49959639d (diff) | |
| download | perlweeklychallenge-club-11af07e28eacf5bfec1ee542c1dbd7b8d1e71291.tar.gz perlweeklychallenge-club-11af07e28eacf5bfec1ee542c1dbd7b8d1e71291.tar.bz2 perlweeklychallenge-club-11af07e28eacf5bfec1ee542c1dbd7b8d1e71291.zip | |
Merge pull request #3962 from stuart-little/stuart-little_110_perl
1st commit on 110_perl
| -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 |
