-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThe_Name_Game
executable file
·60 lines (49 loc) · 1.09 KB
/
The_Name_Game
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/local/bin/perl
#u# http://rosettacode.org/wiki/The_Name_Game
#c# 2019-03-21 <RC, 2019-03-21 >RC
#p# OK
#n# didn't change the logic, just made it more idiomatic Perl
use strict;
use warnings;
use feature 'say';
my $result;
sub printVerse {
my $x = ucfirst lc shift;
my $x0 = substr $x, 0, 1;
my $y = $x0 =~ /[AEIOU]/ ? lc $x : substr $x, 1;
my $b = $x0 eq 'B' ? $y : 'b' . $y;
my $f = $x0 eq 'F' ? $y : 'f' . $y;
my $m = $x0 eq 'M' ? $y : 'm' . $y;
$result .= "$x, $x, bo-$b\n" . "Banana-fana fo-$f\n" . "Fee-fi-mo-$m\n" . "$x!\n\n";
}
printVerse($_) for <Gary Earl Billy Felix Mary Steve>;
say $result;
my $ref = <<'EOD';
Gary, Gary, bo-bary
Banana-fana fo-fary
Fee-fi-mo-mary
Gary!
Earl, Earl, bo-bearl
Banana-fana fo-fearl
Fee-fi-mo-mearl
Earl!
Billy, Billy, bo-illy
Banana-fana fo-filly
Fee-fi-mo-milly
Billy!
Felix, Felix, bo-belix
Banana-fana fo-elix
Fee-fi-mo-melix
Felix!
Mary, Mary, bo-bary
Banana-fana fo-fary
Fee-fi-mo-ary
Mary!
Steve, Steve, bo-bteve
Banana-fana fo-fteve
Fee-fi-mo-mteve
Steve!
EOD
use Test::More;
is ($result, $ref);
done_testing;