diff options
| -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 |
4 files changed, 59 insertions, 2 deletions
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); |
