diff options
| -rwxr-xr-x | challenge-063/e-choroba/perl/ch-1.pl | 15 | ||||
| -rwxr-xr-x | challenge-063/e-choroba/perl/ch-2.pl | 21 |
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-063/e-choroba/perl/ch-1.pl b/challenge-063/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..93a9104abb --- /dev/null +++ b/challenge-063/e-choroba/perl/ch-1.pl @@ -0,0 +1,15 @@ +#!/usr/bin/perl +use warnings; +use strict; + +sub last_word { + my ($string, $re) = @_; + return (grep /$re/, split ' ', $string)[-1] +} + +use Test::More tests => 4; + +is last_word(' hello world', qr/[ea]l/), 'hello'; +is last_word("Don't match too much, Chet!", qr/ch.t/i), 'Chet!'; +is last_word("spaces in regexp won't match", qr/in re/), undef; +is last_word( join(' ', 1..1e6), qr/^(3.*?){3}/), '399933'; diff --git a/challenge-063/e-choroba/perl/ch-2.pl b/challenge-063/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..3281a5f2e7 --- /dev/null +++ b/challenge-063/e-choroba/perl/ch-2.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl +use warnings; +use strict; + +sub rotate { + my ($word) = @_; + my $length = length $word; + my $original = $word; + my $i = 0; + do { + $word .= substr $word, 0, ++$i % $length, ""; + # print "$i: $word\n"; + } until $word eq $original; + return $i +} + +use Test::More; + +is rotate('xyxx'), 7; + +done_testing(); |
