diff options
| author | robbie-hatley <Robbie.Hatley@gmail.com> | 2023-10-18 20:37:52 -0700 |
|---|---|---|
| committer | robbie-hatley <Robbie.Hatley@gmail.com> | 2023-10-18 20:37:52 -0700 |
| commit | c2336ca8b372f4049caca0b308c74ef4cd5defb7 (patch) | |
| tree | e4248f91901b6c1f56846fd2ed64c0199bd57b53 | |
| parent | 138cc390eeaef912722e4844cbad172d40d7219b (diff) | |
| download | perlweeklychallenge-club-c2336ca8b372f4049caca0b308c74ef4cd5defb7.tar.gz perlweeklychallenge-club-c2336ca8b372f4049caca0b308c74ef4cd5defb7.tar.bz2 perlweeklychallenge-club-c2336ca8b372f4049caca0b308c74ef4cd5defb7.zip | |
Improved consistency check.
| -rwxr-xr-x | challenge-239/robbie-hatley/perl/ch-2.pl | 6 |
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; } # ------------------------------------------------------------------------------------------------------------ |
