aboutsummaryrefslogtreecommitdiff
path: root/challenge-005/john-barrett/perl5/ch-1.pl
blob: 0e920a401143c370b8a3c087890d45da255ad154 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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;