From d80e9ac1f7ac30de8be1ebb96306ef2db5603f95 Mon Sep 17 00:00:00 2001 From: CY Fung Date: Mon, 17 Jul 2023 06:00:01 +0800 Subject: Week 225 Task 1 --- challenge-225/cheok-yin-fung/perl/ch-1.pl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 challenge-225/cheok-yin-fung/perl/ch-1.pl 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."]); -- cgit