diff options
Diffstat (limited to 'challenge-005/john-barrett/perl5/ch-1.pl')
| -rwxr-xr-x | challenge-005/john-barrett/perl5/ch-1.pl | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-005/john-barrett/perl5/ch-1.pl b/challenge-005/john-barrett/perl5/ch-1.pl new file mode 100755 index 0000000000..6da945d981 --- /dev/null +++ b/challenge-005/john-barrett/perl5/ch-1.pl @@ -0,0 +1,20 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use autodie; + +my $word = sortedlc( $ARGV[0] ); +my $wordlength = length $word; + +sub sortedlc { join '', sort { $a cmp $b } split '', lc $_[0] } + +sub is_anagram { + my ( $dictword ) = @_; + return 0 if length $dictword != $wordlength; + $word eq sortedlc $dictword; +} + +open my $fh, '<:encoding(UTF-8)', '/usr/share/dict/words'; +chomp( my @dict = <$fh> ); +print "$_\n" for grep { is_anagram( $_ ) } @dict; |
