aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2021-10-14 03:20:28 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2021-10-14 03:20:28 +0100
commit93b3e9f803c45403f40a0dbb6018706de540e9d2 (patch)
tree4066c15519b9e4ea11f7fcc9a2064a565c77deda
parent97bfd2994e4193f6eb9a4397e4fe5cf733b7ca6b (diff)
downloadperlweeklychallenge-club-93b3e9f803c45403f40a0dbb6018706de540e9d2.tar.gz
perlweeklychallenge-club-93b3e9f803c45403f40a0dbb6018706de540e9d2.tar.bz2
perlweeklychallenge-club-93b3e9f803c45403f40a0dbb6018706de540e9d2.zip
- Updated headers as suggested by Colin.
-rwxr-xr-xchallenge-131/peter-campbell-smith/perl/ch-1.pl56
-rwxr-xr-xchallenge-131/peter-campbell-smith/perl/ch-2.pl36
2 files changed, 46 insertions, 46 deletions
diff --git a/challenge-131/peter-campbell-smith/perl/ch-1.pl b/challenge-131/peter-campbell-smith/perl/ch-1.pl
index e7f902759b..17b15e8966 100755
--- a/challenge-131/peter-campbell-smith/perl/ch-1.pl
+++ b/challenge-131/peter-campbell-smith/perl/ch-1.pl
@@ -3,44 +3,42 @@ use strict;
use warnings;
use v5.10;
-# PWC 131 task 2 - Peter Campbell Smith - 2021-09-20
+# PWC 131 task 1 - Peter Campbell Smith - 2021-09-20
-# You are given a string of delimiter pairs and a string to search.
-
-# Write a script to return two strings, the first with any characters matching
-# the “opening character” set, the second with any matching the “closing character” set.
+# You are given a sorted list of unique positive integers.
+# Write a script to return list of arrays where the arrays are consecutive integers.
my ($delimiter_pairs, $search_string, $openers, $closers);
# loop over input values
until (eof(DATA)) {
- $delimiter_pairs = <DATA>;;
- $search_string = <DATA>;
- chop($delimiter_pairs, $search_string);
- do_task();
+ $delimiter_pairs = <DATA>;;
+ $search_string = <DATA>;
+ chop($delimiter_pairs, $search_string);
+ do_task();
}
sub do_task {
-
- my ($openers, $closers, $opens, $closes);
-
- # copy the search string
- $openers = $closers = $search_string;
-
- # pick off the delimiters in pairs and make strings of the opening and closing characters
- while ($delimiter_pairs =~ m|(.)(.)|g) {
- $opens .= $1;
- $closes .= $2;
- }
-
- # remove all but the opening characters from $openers and similarly with $closers
- $openers =~ s|[^\Q$opens\E]||g;
- $closers =~ s|[^\Q$closes\E]||g;
-
- say qq[\nDelimiter pairs: $delimiter_pairs];
- say qq[Search string: $search_string];
- say qq[Openers: $openers];
- say qq[Closers: $closers];
+
+ my ($openers, $closers, $opens, $closes);
+
+ # copy the search string
+ $openers = $closers = $search_string;
+
+ # pick off the delimiters in pairs and make strings of the opening and closing characters
+ while ($delimiter_pairs =~ m|(.)(.)|g) {
+ $opens .= $1;
+ $closes .= $2;
+ }
+
+ # remove all but the opening characters from $openers and similarly with $closers
+ $openers =~ s|[^\Q$opens\E]||g;
+ $closers =~ s|[^\Q$closes\E]||g;
+
+ say qq[\nDelimiter pairs: $delimiter_pairs];
+ say qq[Search string: $search_string];
+ say qq[Openers: $openers];
+ say qq[Closers: $closers];
}
__DATA__
diff --git a/challenge-131/peter-campbell-smith/perl/ch-2.pl b/challenge-131/peter-campbell-smith/perl/ch-2.pl
index 1c364e87dc..bc22d0b343 100755
--- a/challenge-131/peter-campbell-smith/perl/ch-2.pl
+++ b/challenge-131/peter-campbell-smith/perl/ch-2.pl
@@ -3,32 +3,34 @@ use strict;
use warnings;
use v5.10;
-# PWC 131 task 1 - Peter Campbell Smith - 2021-09-20
+# PWC 131 task 2 - Peter Campbell Smith - 2021-09-20
-# You are given a sorted list of unique positive integers.
-# Write a script to return list of arrays where the arrays are consecutive integers.
+# You are given a string of delimiter pairs and a string to search.
+
+# Write a script to return two strings, the first with any characters matching
+# the “opening character” set, the second with any matching the “closing character” set.
my $input;
# loop over input examples
until (eof(DATA)) {
- $input = <DATA>;
- chop $input;
- do_task();
+ $input = <DATA>;
+ chop $input;
+ do_task();
}
sub do_task {
-
- my ($prev, $output);
-
- # loop over list
- $prev = -1;
- while ($input =~ m|(\d+)|g) { # consecutive # non-consecutive
- $output .= ($1 == ($prev + 1)) ? ", $1" : "], [$1";
- $prev = $1;
- }
- $output =~ s|...|(|; # tidy the start of $output
- say "\nInput: ($input)\nOutput: $output])";
+
+ my ($prev, $output);
+
+ # loop over list
+ $prev = -1;
+ while ($input =~ m|(\d+)|g) { # consecutive # non-consecutive
+ $output .= ($1 == ($prev + 1)) ? ", $1" : "], [$1";
+ $prev = $1;
+ }
+ $output =~ s|...|(|; # tidy the start of $output
+ say "\nInput: ($input)\nOutput: $output])";
}
__DATA__