diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-04-26 08:12:34 -0400 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-04-26 08:12:34 -0400 |
| commit | 34595087f49d6292a09dfa9452efe1e49959639d (patch) | |
| tree | 4295f391f96e6199add9f9f9936f10fa6737a746 | |
| parent | 1ff197d81f941c3dd35d77bec8a0326807e8d2b1 (diff) | |
| download | perlweeklychallenge-club-34595087f49d6292a09dfa9452efe1e49959639d.tar.gz perlweeklychallenge-club-34595087f49d6292a09dfa9452efe1e49959639d.tar.bz2 perlweeklychallenge-club-34595087f49d6292a09dfa9452efe1e49959639d.zip | |
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 |
