diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-10-03 17:45:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-03 17:45:02 +0100 |
| commit | fee6a412f87be22468a59bf308d2d08f234b46de (patch) | |
| tree | 910eb5175466f27c0d9a69d06cad3adcf5929d60 | |
| parent | 73886c60216f15232fb3c7a196a08ca1ce3d2307 (diff) | |
| parent | 87577ba46615d972d7a7a4701785e49a93cceac7 (diff) | |
| download | perlweeklychallenge-club-fee6a412f87be22468a59bf308d2d08f234b46de.tar.gz perlweeklychallenge-club-fee6a412f87be22468a59bf308d2d08f234b46de.tar.bz2 perlweeklychallenge-club-fee6a412f87be22468a59bf308d2d08f234b46de.zip | |
Merge pull request #6837 from pjcs00/wk185
Week 185 solutions
| -rw-r--r-- | challenge-185/peter-campbell-smith/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-185/peter-campbell-smith/perl/ch-1.pl | 22 | ||||
| -rwxr-xr-x | challenge-185/peter-campbell-smith/perl/ch-2.pl | 37 |
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) . ')'; +} |
