diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-03-06 18:37:41 +0100 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-03-10 15:39:43 +0100 |
| commit | b77876aa95b2462fdf2af2113cda1257b7a13fad (patch) | |
| tree | 58fafdf492fc734f0906fd78c965c9a888edfe46 | |
| parent | f2e33c0038917ad43651d0c4e8b0bb310eaed541 (diff) | |
| download | perlweeklychallenge-club-b77876aa95b2462fdf2af2113cda1257b7a13fad.tar.gz perlweeklychallenge-club-b77876aa95b2462fdf2af2113cda1257b7a13fad.tar.bz2 perlweeklychallenge-club-b77876aa95b2462fdf2af2113cda1257b7a13fad.zip | |
Solution to task 1
| -rwxr-xr-x | challenge-207/jo-37/perl/ch-1.pl | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/challenge-207/jo-37/perl/ch-1.pl b/challenge-207/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..6138b90adb --- /dev/null +++ b/challenge-207/jo-37/perl/ch-1.pl @@ -0,0 +1,56 @@ +#!/usr/bin/perl -s + +use v5.16; +use Test2::V0; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV; +usage: $0 [-examples] [-tests] [-verbose] [WORD...] + +-examples + run the examples from the challenge + +-tests + run some tests + +WORD... + filter given words for those consisting of letters from a single + keyboard row only + +EOS + + +### Input and Output + +say for keyboard_words(@ARGV); + + +### Implementation + +sub keyboard_words { + # Match words against keyboard rows. + grep /^(?i:[qwertyuiop]+|[asdfghjkl]+|[zxcvbnm]+)$/, @_; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is [keyboard_words(qw(Hello Alaska Dad Peace))], + [qw(Alaska Dad)], 'example 1'; + is [keyboard_words(qw(OMG Bye))], [], 'example 2'; + } + + SKIP: { + skip "tests" unless $tests; + } + + done_testing; + exit; +} |
