aboutsummaryrefslogtreecommitdiff
path: root/challenge-063
diff options
context:
space:
mode:
authorsangeet <sangeet.kar@gmail.com>2020-06-02 10:05:58 +0000
committersangeet <sangeet.kar@gmail.com>2020-06-02 10:05:58 +0000
commit640b2248d9135318bfbac1407594e7454fcdd962 (patch)
tree1fe6c55766f588a611708c86d7fbeaa91f036bc7 /challenge-063
parent3f605af6c19ce1dc8ba98d73a4c33ee779aab2c7 (diff)
downloadperlweeklychallenge-club-640b2248d9135318bfbac1407594e7454fcdd962.tar.gz
perlweeklychallenge-club-640b2248d9135318bfbac1407594e7454fcdd962.tar.bz2
perlweeklychallenge-club-640b2248d9135318bfbac1407594e7454fcdd962.zip
Ch1 & Ch2 in Perl
Diffstat (limited to 'challenge-063')
-rwxr-xr-xchallenge-063/sangeet-kar/perl/ch-1.pl21
-rwxr-xr-xchallenge-063/sangeet-kar/perl/ch-2.pl18
2 files changed, 39 insertions, 0 deletions
diff --git a/challenge-063/sangeet-kar/perl/ch-1.pl b/challenge-063/sangeet-kar/perl/ch-1.pl
new file mode 100755
index 0000000000..986f399b2d
--- /dev/null
+++ b/challenge-063/sangeet-kar/perl/ch-1.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::More;
+
+sub last_word {
+ my ( $string, $regex ) = @_;
+ my @words = split /\s+/, $string;
+ foreach ( reverse @words ) {
+ return $_ if $_ =~ $regex;
+ }
+ return undef;
+}
+
+is( last_word( ' hello world', qr/[ea]l/ ), 'hello', 'hello world' );
+is( last_word( "Don't match too much, Chet!", qr/ch.t/i ), 'Chet!', 'Chet!' );
+is( last_word( "spaces in regexp won't match", qr/in re/ ), undef, 'undef' );
+is( last_word( join( ' ', 1 .. 1e6 ), qr/^(3.*?){3}/ ),
+ '399933', 'long list of nums' );
+done_testing;
diff --git a/challenge-063/sangeet-kar/perl/ch-2.pl b/challenge-063/sangeet-kar/perl/ch-2.pl
new file mode 100755
index 0000000000..0d250f739d
--- /dev/null
+++ b/challenge-063/sangeet-kar/perl/ch-2.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl
+
+sub rot {
+ my ( $string, $n ) = @_;
+ substr( $string, $n ) . substr( $string, 0, $n );
+}
+
+my $input = $ARGV[0] // 'xyxx';
+
+my $tmp = $input;
+for ( my $i = 1 ; ; $i++ ) {
+ $tmp = rot( $tmp, $i % length($input) );
+ if ( $tmp eq $input ) {
+ print $i;
+ last;
+ }
+}
+