diff options
| author | John Barrett <john@jbrt.org> | 2019-04-15 22:09:57 +0100 |
|---|---|---|
| committer | John Barrett <john@jbrt.org> | 2019-04-15 22:19:33 +0100 |
| commit | 1a973fe01229adfce9a048893fb894030c4ac2c4 (patch) | |
| tree | 9f9a736e3cfe8bf4274b81115372ac4d2a2686a4 | |
| parent | 60e3e497a47959c2e13f900379a06bb133d7bb32 (diff) | |
| download | perlweeklychallenge-club-1a973fe01229adfce9a048893fb894030c4ac2c4.tar.gz perlweeklychallenge-club-1a973fe01229adfce9a048893fb894030c4ac2c4.tar.bz2 perlweeklychallenge-club-1a973fe01229adfce9a048893fb894030c4ac2c4.zip | |
Challenge 4 part 2
| -rwxr-xr-x[-rw-r--r--] | challenge-004/john-barrett/perl5/ch-1.pl | 0 | ||||
| -rwxr-xr-x | challenge-004/john-barrett/perl5/ch-2.pl | 31 |
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-004/john-barrett/perl5/ch-1.pl b/challenge-004/john-barrett/perl5/ch-1.pl index 51356fba61..51356fba61 100644..100755 --- a/challenge-004/john-barrett/perl5/ch-1.pl +++ b/challenge-004/john-barrett/perl5/ch-1.pl diff --git a/challenge-004/john-barrett/perl5/ch-2.pl b/challenge-004/john-barrett/perl5/ch-2.pl new file mode 100755 index 0000000000..840eeba777 --- /dev/null +++ b/challenge-004/john-barrett/perl5/ch-2.pl @@ -0,0 +1,31 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +print "Usage: $0 letters to find in dict\n" and exit unless @ARGV; + +my $fn = '/usr/share/dict/words'; +my $findletters; +$findletters->{$_}++ for map { map { lc } split '' } @ARGV; + +my @found; + +open my $fh, '<', $fn; + +WORD: while ( my $word = <$fh> ) { + chomp $word; + my $wordletters; + $wordletters->{$_}++ for map { lc } split '', $word; + # Change this to 'keys %{ $findletters }' to find + # all words containing the specified letters. + # This finds all words composed of the specified letters + # which I think fulfills "you don’t have to use all the letters" + for my $letter ( keys %{ $wordletters } ) { + no warnings 'uninitialized'; + next WORD unless $wordletters->{ $letter } <= $findletters->{ $letter }; + } + push @found, $word; +} + +print "$_\n" for @found; |
