diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-09-02 11:38:15 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-02 11:38:15 +0100 |
| commit | ec87dd941ff7cc91a42af9e70e4aa2bacbf7d935 (patch) | |
| tree | fac318fdcbe074f6472b2bd34175a1c100a081e0 | |
| parent | 462814805ca3a17488a492693a6af666c2c0b0db (diff) | |
| parent | 8422e1828e6d2eaa04e9efef795f315edd9b6d58 (diff) | |
| download | perlweeklychallenge-club-ec87dd941ff7cc91a42af9e70e4aa2bacbf7d935.tar.gz perlweeklychallenge-club-ec87dd941ff7cc91a42af9e70e4aa2bacbf7d935.tar.bz2 perlweeklychallenge-club-ec87dd941ff7cc91a42af9e70e4aa2bacbf7d935.zip | |
Merge pull request #589 from Scimon/master
Apparently an empty file runs fine in both perl5 and perl6
| -rw-r--r-- | challenge-024/simon-proctor/perl5/ch-1.pl | 0 | ||||
| -rw-r--r-- | challenge-024/simon-proctor/perl6/ch-1.p6 | 0 | ||||
| -rw-r--r-- | challenge-024/simon-proctor/perl6/ch-2.p6 | 50 |
3 files changed, 50 insertions, 0 deletions
diff --git a/challenge-024/simon-proctor/perl5/ch-1.pl b/challenge-024/simon-proctor/perl5/ch-1.pl new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-024/simon-proctor/perl5/ch-1.pl diff --git a/challenge-024/simon-proctor/perl6/ch-1.p6 b/challenge-024/simon-proctor/perl6/ch-1.p6 new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-024/simon-proctor/perl6/ch-1.p6 diff --git a/challenge-024/simon-proctor/perl6/ch-2.p6 b/challenge-024/simon-proctor/perl6/ch-2.p6 new file mode 100644 index 0000000000..d44fbc40fc --- /dev/null +++ b/challenge-024/simon-proctor/perl6/ch-2.p6 @@ -0,0 +1,50 @@ +#!/usr/bin/env perl6 + +use v6; +use JSON::Fast; + +my %*SUB-MAIN-OPTS = :named-anywhere; + +#| Display Help information +multi sub MAIN ( Bool :h(:$help) where so * ) { + say $*USAGE; +} + +subset FileExists of Str where { $_.IO.e && $_.IO.f }; + +#| Work out the reverse index for the given documents +multi sub MAIN ( + *@documents where { @documents.all ~~ FileExists }, #= List of documents to process + Int :$min-length = 3, #= Minimum word length to count for inclusion in the index. Default is 3 characters. +) { + my %index; + my $word-channel = Channel.new; + my @promises; + + for @documents -> $path { + @promises.push( + start { + my $res-path = $path.IO.resolve.Str; + for $path.IO.words -> $word is copy { + $word ~~ s:g!<[\W]>!!; + next unless $word.chars >= $min-length; + $word-channel.send( ( $word.fc, $res-path ) ); + } + } + ); + } + + my $reactor = start react { + whenever $word-channel -> ( $word, $path ) { + %index{$word} //= SetHash.new; + %index{$word}.{$path} = True; + } + } + await @promises; + $word-channel.close; + await $reactor; + + %index = %index.map( { $_.key => $_.value.keys } ); + say to-json( %index ); +} + |
