aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-185/peter-campbell-smith/blog.txt1
-rwxr-xr-xchallenge-185/peter-campbell-smith/perl/ch-1.pl22
-rwxr-xr-xchallenge-185/peter-campbell-smith/perl/ch-2.pl37
3 files changed, 60 insertions, 0 deletions
diff --git a/challenge-185/peter-campbell-smith/blog.txt b/challenge-185/peter-campbell-smith/blog.txt
new file mode 100644
index 0000000000..de5f65dc75
--- /dev/null
+++ b/challenge-185/peter-campbell-smith/blog.txt
@@ -0,0 +1 @@
+https://pjcs-pwc.blogspot.com/2022/10/manipulating-characters.html
diff --git a/challenge-185/peter-campbell-smith/perl/ch-1.pl b/challenge-185/peter-campbell-smith/perl/ch-1.pl
new file mode 100755
index 0000000000..1f2cdefd68
--- /dev/null
+++ b/challenge-185/peter-campbell-smith/perl/ch-1.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/perl
+
+# Peter Campbell Smith - 2022-10-02
+# PWC 185 task 1
+
+use v5.28;
+use utf8;
+use warnings;
+
+# You are given MAC address in the form hhhh.hhhh.hhhh.
+# Write a script to convert the address to the form hh:hh:hh:hh:hh:hh.
+
+# Blog: https://pjcs-pwc.blogspot.com/2022/10/manipulating-characters.html
+
+my (@tests, $test);
+
+@tests = ('1ac2.34f0.b1c2', 'abc1.20f1.345a');
+
+# just do it
+for $test (@tests) {
+ say $test =~ m|^(..)(..).(..)(..).(..)(..)$| ? qq[\nInput: $test\nOutput: $1:$2:$3:$4:$5:$6]: 'Invalid format';
+}
diff --git a/challenge-185/peter-campbell-smith/perl/ch-2.pl b/challenge-185/peter-campbell-smith/perl/ch-2.pl
new file mode 100755
index 0000000000..b972199ad5
--- /dev/null
+++ b/challenge-185/peter-campbell-smith/perl/ch-2.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+
+# Peter Campbell Smith - 2022-10-02
+# PWC 185 task 1
+
+use v5.28;
+use utf8;
+use warnings;
+binmode(STDOUT, ':utf8');
+
+# You are given a list of random strings.
+# Write a script to change the first four characters matching [a-z0-9] to x and keep the rest as it is.
+
+# Blog: https://pjcs-pwc.blogspot.com/2022/10/manipulating-characters.html
+
+my (@tests, $test, @list, $item, $j, $output);
+
+@tests = (['ab-cde-123', '123.abc.420', '3abc-0010.xy'],
+ ['A5h&kP.....z', '!"£$%^&*()', 'xxxx00000', 'abcd', 'ǀØΨ£‡⁇ aaaa']);
+
+# loop over tests
+for $test (@tests) {
+ @list = @$test;
+
+ # initialise
+ say qq[\nInput: \@list = (] . join(', ', @list) . ')';
+ $output = '';
+
+ # loop over items within test
+ for $item (@list) {
+ $item =~ s|^(.*?)[a-z0-9](.*?)[a-z0-9](.*?)[a-z0-9](.*?)[a-z0-9]|$1x$2x$3x$4x|;
+ $output .= qq[$item, ];
+ }
+
+ # and print the answer
+ say qq[Output: (] . substr($output, 0, -2) . ')';
+}