From 38636f3ebb8d38bf030d4108ea5d0e08b72da11d Mon Sep 17 00:00:00 2001 From: John Barrett Date: Wed, 24 Apr 2019 10:10:18 +0100 Subject: Challenge 5 part 1 - first pass --- challenge-005/john-barrett/perl5/ch-1.pl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 challenge-005/john-barrett/perl5/ch-1.pl (limited to 'challenge-005') 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..0e920a4011 --- /dev/null +++ b/challenge-005/john-barrett/perl5/ch-1.pl @@ -0,0 +1,18 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use autodie; + +my $word = join '', sort { $a cmp $b } split '', lc $ARGV[0]; +my $wordlength = length $word; + +sub is_anagram { + my ( $dictword ) = @_; + return 0 if length $dictword != $wordlength; + $word eq join '', sort { $a cmp $b } split '', lc $dictword; +} + +open my $fh, '<:encoding(UTF-8)', '/usr/share/dict/words'; +chomp( my @dict = <$fh> ); +printf "$_\n" for grep { is_anagram( $_ ) } @dict; -- cgit