diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2020-06-01 20:30:04 -0400 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2020-06-01 20:30:04 -0400 |
| commit | 0f5bdfb7781cc28c490df9f527e86e8515750985 (patch) | |
| tree | 289bdd8007aeb1bdd6006838290cd5db8b2b72c6 | |
| parent | 2196798257f7c9d89709630f22bd750067f63afb (diff) | |
| download | perlweeklychallenge-club-0f5bdfb7781cc28c490df9f527e86e8515750985.tar.gz perlweeklychallenge-club-0f5bdfb7781cc28c490df9f527e86e8515750985.tar.bz2 perlweeklychallenge-club-0f5bdfb7781cc28c490df9f527e86e8515750985.zip | |
challenge 63
| -rwxr-xr-x | challenge-063/dave-jacoby/perl/ch-1.pl | 30 | ||||
| -rwxr-xr-x | challenge-063/dave-jacoby/perl/ch-2.pl | 34 |
2 files changed, 64 insertions, 0 deletions
diff --git a/challenge-063/dave-jacoby/perl/ch-1.pl b/challenge-063/dave-jacoby/perl/ch-1.pl new file mode 100755 index 0000000000..be3a29e8e1 --- /dev/null +++ b/challenge-063/dave-jacoby/perl/ch-1.pl @@ -0,0 +1,30 @@ +#!/usr/bin/env perl + +# USAGE: ch-1.pl [-u] [file ...] + +use strict; +use warnings; +use utf8; +use feature qw{ fc postderef say signatures state switch }; +no warnings qw{ experimental }; + +use Getopt::Long; +use Carp; +use JSON; + +my $json = JSON->new->canonical->allow_nonref->pretty->space_after; + +say last_word(); +say last_word( ' hello world', qr/[ea]l/ ) || 'undef'; # 'hello' +say last_word( "Don't match too much, Chet!", qr/ch.t/i ) || 'undef'; # 'Chet!' +say last_word( "spaces in regexp won't match", qr/in re/ ) || 'undef'; # undef +say last_word( join( ' ', 1 .. 1e6 ), qr/^(3.*?){3}/ ) || 'undef'; # '399933' + +sub last_word ( $string = ' strang string', $regex = qr/\w/ ) { + my ($output) = + reverse + grep { /$regex/ } + grep { /\S/ } + split /\s+/, $string; + return $output; +} diff --git a/challenge-063/dave-jacoby/perl/ch-2.pl b/challenge-063/dave-jacoby/perl/ch-2.pl new file mode 100755 index 0000000000..c4413d7d29 --- /dev/null +++ b/challenge-063/dave-jacoby/perl/ch-2.pl @@ -0,0 +1,34 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use utf8; +use feature qw{ postderef say signatures state switch }; +no warnings qw{ experimental }; + +use Carp; +use JSON; +my $json = JSON->new->canonical->allow_nonref->pretty->space_after; + +my $word = 'xyxx'; + +say rotate_string($word); + +sub rotate_string( $word ) { + say $word; + my $l = length $word; + my $c = 0; + my $copy = $word; + while (1) { + my $m = $c % $l; + $c++; + my @copy = split //, $copy; + for ( 0 .. $m ) { + push @copy, shift @copy; + } + $copy = join '', @copy; + return $c if $word eq $copy; + exit if $c > 10; + } + return 1; +} |
