aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-185/perlboy1967/perl/ch-1.pl34
-rwxr-xr-xchallenge-185/perlboy1967/perl/ch-2.pl41
2 files changed, 75 insertions, 0 deletions
diff --git a/challenge-185/perlboy1967/perl/ch-1.pl b/challenge-185/perlboy1967/perl/ch-1.pl
new file mode 100755
index 0000000000..fc0b032225
--- /dev/null
+++ b/challenge-185/perlboy1967/perl/ch-1.pl
@@ -0,0 +1,34 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 185
+ - https://theweeklychallenge.org/blog/perl-weekly-challenge-185/#TASK2
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 2: Mask Code
+Submitted by: Mohammad S Anwar
+
+You are given a list of codes in many random format.
+
+Write a script to mask first four characters (a-z,0-9) and keep the rest as it is.
+
+=cut
+
+use v5.16;
+use warnings;
+
+use Test::More;
+
+
+sub macFormat ($) {
+ return join(':',$1,$2,$3,$4,$5,$6)
+ if ($_[0] =~ /(?i)^([0-9a-f]{2})([0-9a-f]{2})\.([0-9a-f]{2})([0-9a-f]{2})\.([0-9a-f]{2})([0-9a-f]{2})$/);
+}
+
+
+is(macFormat('1ac2.34f0.b1c2'),'1a:c2:34:f0:b1:c2');
+is(macFormat('ABC1.20F1.345A'),'AB:C1:20:F1:34:5A');
+
+done_testing;
diff --git a/challenge-185/perlboy1967/perl/ch-2.pl b/challenge-185/perlboy1967/perl/ch-2.pl
new file mode 100755
index 0000000000..e972e05120
--- /dev/null
+++ b/challenge-185/perlboy1967/perl/ch-2.pl
@@ -0,0 +1,41 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 185
+ - https://theweeklychallenge.org/blog/perl-weekly-challenge-185/#TASK2
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 2: Mask Code
+Submitted by: Mohammad S Anwar
+
+You are given a list of codes in many random format.
+
+Write a script to mask first four characters (a-z,0-9) and keep the rest as it is.
+
+=cut
+
+use v5.16;
+use warnings;
+
+use Test::More;
+use Test::Deep qw(cmp_deeply);
+
+
+sub maskcode {
+ state $re = '([^0-9a-z]*)([0-9a-z])' x 4;
+ my @r;
+ for (@_) {
+ push(@r,s/^$re/$1x$3x$5x$7x/or);
+ }
+ @r;
+}
+
+
+cmp_deeply([maskcode('ab-cde-123', '123.abc.420', '3abc-0010.xy')],
+ ['xx-xxe-123', 'xxx.xbc.420', 'xxxx-0010.xy']);
+cmp_deeply([maskcode('1234567.a', 'a-1234-bc', 'a.b.c.d.e.f')],
+ ['xxxx567.a', 'x-xxx4-bc', 'x.x.x.x.e.f']);
+
+done_testing;