diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-04-27 17:23:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-27 17:23:17 +0100 |
| commit | 3ecc538993f7a6186028ee26449fb81ac4117bc5 (patch) | |
| tree | 41a1284ff7a1a23693660e0aac37766b2669bc12 | |
| parent | 77c39151cd978586279d5cbb1e6e571980a018e6 (diff) | |
| parent | b62cd56fbb11e6073324daf59961dfa56279ee07 (diff) | |
| download | perlweeklychallenge-club-3ecc538993f7a6186028ee26449fb81ac4117bc5.tar.gz perlweeklychallenge-club-3ecc538993f7a6186028ee26449fb81ac4117bc5.tar.bz2 perlweeklychallenge-club-3ecc538993f7a6186028ee26449fb81ac4117bc5.zip | |
Merge pull request #3971 from simongreen-net/swg-110
sgreen solution to challenge 110 and blog for 109
| -rw-r--r-- | challenge-109/sgreen/README.md | 2 | ||||
| -rw-r--r-- | challenge-109/sgreen/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-110/sgreen/README.md | 4 | ||||
| -rw-r--r-- | challenge-110/sgreen/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-110/sgreen/perl/ch-1.pl | 23 | ||||
| -rwxr-xr-x | challenge-110/sgreen/perl/ch-2.pl | 33 |
6 files changed, 61 insertions, 3 deletions
diff --git a/challenge-109/sgreen/README.md b/challenge-109/sgreen/README.md index 94ad2ed1db..b0c87bc76f 100644 --- a/challenge-109/sgreen/README.md +++ b/challenge-109/sgreen/README.md @@ -1,3 +1,3 @@ # The Weekly Challenge 109 -Solution by Simon Green. [Blog]() +Solution by Simon Green. [Blog](https://dev.to/simongreennet/weekly-challenge-109-4je2) diff --git a/challenge-109/sgreen/blog.txt b/challenge-109/sgreen/blog.txt new file mode 100644 index 0000000000..58dcac2565 --- /dev/null +++ b/challenge-109/sgreen/blog.txt @@ -0,0 +1 @@ +https://dev.to/simongreennet/weekly-challenge-109-4je2 diff --git a/challenge-110/sgreen/README.md b/challenge-110/sgreen/README.md index 94ad2ed1db..53f7bdfaba 100644 --- a/challenge-110/sgreen/README.md +++ b/challenge-110/sgreen/README.md @@ -1,3 +1,3 @@ -# The Weekly Challenge 109 +# The Weekly Challenge 110 -Solution by Simon Green. [Blog]() +Solution by Simon Green. [Blog](https://dev.to/simongreennet/weekly-challenge-110-22ao) diff --git a/challenge-110/sgreen/blog.txt b/challenge-110/sgreen/blog.txt new file mode 100644 index 0000000000..2dd0651112 --- /dev/null +++ b/challenge-110/sgreen/blog.txt @@ -0,0 +1 @@ +https://dev.to/simongreennet/weekly-challenge-110-22ao diff --git a/challenge-110/sgreen/perl/ch-1.pl b/challenge-110/sgreen/perl/ch-1.pl new file mode 100755 index 0000000000..5c420464ee --- /dev/null +++ b/challenge-110/sgreen/perl/ch-1.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use feature 'say'; + +sub main { + my $filename = shift; + die "File does not exist or is not readable\n" unless -f $filename && -r $filename; + + # Open the file + open( my $fh, '<', $filename ) or die "Cannot open $filename: $!"; + + while ( my $line = <$fh> ) { + # Remove the trailing cr/nl characters + chomp $line; + + # Print the line if it is the correct format + say $line if $line =~ /^(?:\+[0-9]{2}|\([0-9]{2}\)|[0-9]{4}) [0-9]{10}$/; + } +} + +main(@ARGV); diff --git a/challenge-110/sgreen/perl/ch-2.pl b/challenge-110/sgreen/perl/ch-2.pl new file mode 100755 index 0000000000..a5354cc5f9 --- /dev/null +++ b/challenge-110/sgreen/perl/ch-2.pl @@ -0,0 +1,33 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use feature 'say'; + +use List::Util 'max'; + +sub main { + my $filename = shift; + die "File does not exist or is not readable\n" unless -f $filename && -r $filename; + + # Open the file + open( my $fh, '<', $filename ) or die "Cannot open $filename: $!"; + + # Read the input into an array + my @lines = (); + while ( my $line = <$fh> ) { + # Remove the trailing cr/nl characters + chomp $line; + push @lines, [ split /,/, $line ]; + } + + # Get the maximum number of values in the rows + my $max = max( map { scalar(@$_) } @lines ); + + # Print each column as a row + for my $col ( 0 .. $max - 1 ) { + say join ',', map { $_->[$col] // '' } @lines; + } +} + +main(@ARGV); |
