aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-110/mohammad-anwar/perl/ch-1.t36
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-110/mohammad-anwar/perl/ch-1.t b/challenge-110/mohammad-anwar/perl/ch-1.t
new file mode 100644
index 0000000000..574305981f
--- /dev/null
+++ b/challenge-110/mohammad-anwar/perl/ch-1.t
@@ -0,0 +1,36 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Deep;
+
+is_deeply( valid_phone_numbers('input-1.txt'),
+ [ '0044 1148820341',
+ ' +44 1148820341',
+ '(44) 1148820341', ] );
+
+done_testing;
+
+sub valid_phone_numbers {
+ my ($file) = @_;
+
+ die "ERROR: Missing input file.\n" unless defined $file;
+
+ open(my $fh, '<:encoding(utf8)', $file)
+ or die "ERROR: Unable to open $file: $!\n";
+
+ my $valid_phone_numbers = [];
+ while (my $row = <$fh>) {
+ chomp $row;
+
+ if ( $row =~ / ( \+\d{2} | \(\d{2}\) | \d{4} ) \s \d{10} /x ) {
+ push @$valid_phone_numbers, $row;
+ }
+ }
+
+ close($fh);
+
+ return $valid_phone_numbers;
+}