diff options
| author | CY Fung <fungcheokyin@gmail.com> | 2023-07-17 06:00:01 +0800 |
|---|---|---|
| committer | CY Fung <fungcheokyin@gmail.com> | 2023-07-17 06:00:01 +0800 |
| commit | d80e9ac1f7ac30de8be1ebb96306ef2db5603f95 (patch) | |
| tree | 36c754c49d84bad652b9d54382ef7eca83d26d08 | |
| parent | 086fe4c1433069d0e47f3fc49a188653f697a95a (diff) | |
| download | perlweeklychallenge-club-d80e9ac1f7ac30de8be1ebb96306ef2db5603f95.tar.gz perlweeklychallenge-club-d80e9ac1f7ac30de8be1ebb96306ef2db5603f95.tar.bz2 perlweeklychallenge-club-d80e9ac1f7ac30de8be1ebb96306ef2db5603f95.zip | |
Week 225 Task 1
| -rw-r--r-- | challenge-225/cheok-yin-fung/perl/ch-1.pl | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-225/cheok-yin-fung/perl/ch-1.pl b/challenge-225/cheok-yin-fung/perl/ch-1.pl new file mode 100644 index 0000000000..19880b7a78 --- /dev/null +++ b/challenge-225/cheok-yin-fung/perl/ch-1.pl @@ -0,0 +1,26 @@ +# The Weekly Challenge 225 +# Task 1 Max Words +use v5.30.0; +use warnings; +use List::Util qw/uniqstr/; + +sub mw { + my @list = $_[0]->@*; + my $max = 0; + s/\p{PosixPunct}/ /g for @list; + for my $sent (@list) { + my @arr; + push @arr, (split /\s+/, $sent); + my $words = uniqstr @arr; + $max = $words if $words > $max; + } + return $max; +} + +use Test::More tests=>2; +ok 8 == mw(["Perl and Raku, belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference."]); +ok 7 == mw(["The Weekly Challenge.", + "Python is the most popular guest language.", + "Team PWC has over 300 members."]); |
