diff options
| author | Fung Cheok Yin <61836418+E7-87-83@users.noreply.github.com> | 2020-06-05 09:09:19 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-05 09:09:19 +0800 |
| commit | 96b68b65c09fbc7d20f8bfaba3b4002f694d1efc (patch) | |
| tree | 655776dbf67196153678e20587f605a87c1d420e /challenge-063 | |
| parent | 866dd4ba4ab6c0493ac11fc205686239f26e3306 (diff) | |
| download | perlweeklychallenge-club-96b68b65c09fbc7d20f8bfaba3b4002f694d1efc.tar.gz perlweeklychallenge-club-96b68b65c09fbc7d20f8bfaba3b4002f694d1efc.tar.bz2 perlweeklychallenge-club-96b68b65c09fbc7d20f8bfaba3b4002f694d1efc.zip | |
Rename ch-1.pl to challenge-063/cheok-yin-fung/ch-1.pl
Diffstat (limited to 'challenge-063')
| -rw-r--r-- | challenge-063/cheok-yin-fung/ch-1.pl | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-063/cheok-yin-fung/ch-1.pl b/challenge-063/cheok-yin-fung/ch-1.pl new file mode 100644 index 0000000000..b0d6011119 --- /dev/null +++ b/challenge-063/cheok-yin-fung/ch-1.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl +use Test::Simple tests => 3; +use strict; + +sub last_word { + my $qr = $_[1]; + my @rwords = reverse split / /, $_[0]; + foreach (@rwords) { + if ($_ =~ $qr) { #why if ($qr) does not work + return $_; + } + } + return undef; +} + +ok ( last_word('hello world', qr/[ea]l/) eq "hello", "Good Hello" ) ; +ok ( last_word("Don't match too much, Chet!", qr/ch.t/i) eq 'Chet!', "Good Chet"); +ok ( last_word( join(' ', 1..1e6), qr/^(3.*?){3}/) eq '399933', "Nice number"); |
