diff options
| author | Simon Proctor <simon.proctor@zpg.co.uk> | 2019-11-04 09:48:35 +0000 |
|---|---|---|
| committer | Simon Proctor <simon.proctor@zpg.co.uk> | 2019-11-04 09:48:35 +0000 |
| commit | 4dc5e0b7b1f170236ebaa940ede9d804dea49614 (patch) | |
| tree | 3798ce5a750e0063e8c820fd75dc4dba6364af08 /challenge-033/simon-proctor | |
| parent | f305be816a6bc96d552ec0151441a8d13ffa0deb (diff) | |
| download | perlweeklychallenge-club-4dc5e0b7b1f170236ebaa940ede9d804dea49614.tar.gz perlweeklychallenge-club-4dc5e0b7b1f170236ebaa940ede9d804dea49614.tar.bz2 perlweeklychallenge-club-4dc5e0b7b1f170236ebaa940ede9d804dea49614.zip | |
Challenge 1 : A-Z Counter
Diffstat (limited to 'challenge-033/simon-proctor')
| -rw-r--r-- | challenge-033/simon-proctor/perl6/ch-1.p6 | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-033/simon-proctor/perl6/ch-1.p6 b/challenge-033/simon-proctor/perl6/ch-1.p6 new file mode 100644 index 0000000000..4c4c567f9e --- /dev/null +++ b/challenge-033/simon-proctor/perl6/ch-1.p6 @@ -0,0 +1,31 @@ +#!/usr/bin/env perl6 + +use v6; + +subset ValidFile of Str where *.IO.f; +my %*SUB-MAIN-OPTS = :named-anywhere; + +#| Print help text +multi sub MAIN( Bool :h($help) where so * ) { + say $*USAGE; +} + +#| Read data from standard out. +#| Returns a list of a-z and the number of times each occurs in the input +multi sub MAIN() { + read-files( IO::CatHandle.new( $*IN ) ); +} + +#| Given a list of filenames reads each in turn +#| Returns a list of a-z and the number of times each occurs in the input +multi sub MAIN( + *@files where all(@files) ~~ ValidFile, #= Files to read +) { + read-files( IO::CatHandle.new( @files ) ); +} + +sub read-files( IO::CatHandle $files ) { + my %results := $files.words.map(*.lc.comb()).flat.grep( { $_ ~~ m!<[a..z]>! } ).Bag; + + .say for ("a".."z").map( { "{$_} : {%results{$_}}" } ); +} |
