aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobbie-hatley <Robbie.Hatley@gmail.com>2023-10-18 20:37:52 -0700
committerrobbie-hatley <Robbie.Hatley@gmail.com>2023-10-18 20:37:52 -0700
commitc2336ca8b372f4049caca0b308c74ef4cd5defb7 (patch)
treee4248f91901b6c1f56846fd2ed64c0199bd57b53
parent138cc390eeaef912722e4844cbad172d40d7219b (diff)
downloadperlweeklychallenge-club-c2336ca8b372f4049caca0b308c74ef4cd5defb7.tar.gz
perlweeklychallenge-club-c2336ca8b372f4049caca0b308c74ef4cd5defb7.tar.bz2
perlweeklychallenge-club-c2336ca8b372f4049caca0b308c74ef4cd5defb7.zip
Improved consistency check.
-rwxr-xr-xchallenge-239/robbie-hatley/perl/ch-2.pl6
1 files changed, 3 insertions, 3 deletions
diff --git a/challenge-239/robbie-hatley/perl/ch-2.pl b/challenge-239/robbie-hatley/perl/ch-2.pl
index 3db5c2fb79..2c53b74455 100755
--- a/challenge-239/robbie-hatley/perl/ch-2.pl
+++ b/challenge-239/robbie-hatley/perl/ch-2.pl
@@ -82,10 +82,10 @@ sub consistent ($aref) {
say "Allowed characters = \"$allowed\"";
my @consistent = ();
# Push strings consisting only of "allowed" characters to @consistent:
- for (@array) {if ($_ =~ m/^[$allowed]+$/) {push @consistent, $_;}}
+ /^[$allowed]+$/ and push @consistent, $_ for @array;
my $n = scalar(@consistent);
- say "$n of the strings in the array are consistent with the allowed characters:";
- say 'Consistent = (' . join(', ', map {"\"$_\""} @consistent) . ')';
+ say "$n of the strings in the array are consistent with the allowed characters.";
+ say 'Consistent = (' . join(', ', map {"\"$_\""} @consistent) . ')' if $n;
}
# ------------------------------------------------------------------------------------------------------------