diff options
| author | Niels van Dijke <perlboy@cpan.org> | 2020-06-01 06:22:16 +0000 |
|---|---|---|
| committer | Niels van Dijke <perlboy@cpan.org> | 2020-06-01 06:22:16 +0000 |
| commit | 6bc322e92ee3b5bfe27893f853cb6be736307a2d (patch) | |
| tree | beddb1f22b735d38968fce91c6f0b3ff06a60061 | |
| parent | faffe66f477214e58cd6543786bdc8026488db0d (diff) | |
| download | perlweeklychallenge-club-6bc322e92ee3b5bfe27893f853cb6be736307a2d.tar.gz perlweeklychallenge-club-6bc322e92ee3b5bfe27893f853cb6be736307a2d.tar.bz2 perlweeklychallenge-club-6bc322e92ee3b5bfe27893f853cb6be736307a2d.zip | |
Task 2
| -rw-r--r-- | challenge-063/perlboy1967/perl/ch-2.pl | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-063/perlboy1967/perl/ch-2.pl b/challenge-063/perlboy1967/perl/ch-2.pl new file mode 100644 index 0000000000..10c617d68d --- /dev/null +++ b/challenge-063/perlboy1967/perl/ch-2.pl @@ -0,0 +1,30 @@ +#!/usr/bin/perl + +# Perl Weekly Challenge - 063 +# +# Task 2 - Rotate String +# +# Author: Niels 'PerlBoy' van Dijke + +use strict; +use warnings; + +# Prototype +sub rotateWord ($$); + +while (<>) { + my ($word, $n) = $_ =~ /(\S+)\s+(\d+)/; + + printf "rotateWord('%s', %d) => '%s'\n", + $word, $n, rotateWord($word, $n); +} + +sub rotateWord ($$) { + my ($word, $rotateNtimes) = @_; + + my @chars = split(//, $word); + + push(@chars, splice(@chars, 0, $rotateNtimes % scalar(@chars))); + + return join('', @chars); +} |
