aboutsummaryrefslogtreecommitdiff
path: root/challenge-110/james-smith/perl/ch-1.pl
blob: 5435cde1b1fe6560ccfddfda1068e447f4440bc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/local/bin/perl

use strict;

use warnings;
use feature qw(say);
use Test::More;

print grep { is_valid_phone_number($_) } <>;

sub is_valid_phone_number {
  return m{\A           # Start of line
           \s*          # Some white-space ?
           (?:          # Prefix - one of:
             [+]\d+ |   #   +{digits}
             00\d+  |   #   00{digits}
             [(]\d+[)]  #   ({digits})
           )
           \s+          # Some white-space
           \d+          # String of numbers
           \s*          # Some white-space ?
           \Z           # End of line
          }x;
}

sub is_valid_phone_number_compact {
  return m{\A\s*(?:[+]\d+|00\d+|[(]\d+[)])\s+\d+\s*\Z};
}