blob: 75d5cf9de3b86b66f2e7243efb61079513094b7e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#!/usr/bin/perl;
use strict;
use warnings;
sub is_anagram {
my ($word1, $word2) = @_;
my $sorted1 = join q{}, sort split(q{}, lc $word1);
my $sorted2 = join q{}, sort split(q{}, lc $word2);
return $sorted1 eq $sorted2;
}
print "Enter a word to find anagrams for: ";
chomp(my $compare_word = <>);
print "Enter a word: ";
while (my $user_input = <>) {
chomp $user_input;
if (is_anagram($compare_word, $user_input)) {
print "$user_input and $compare_word are anagrams.\n";
}
print "Enter a word: ";
}
__END__
|