-
Notifications
You must be signed in to change notification settings - Fork 319
/
ch-1.pl
86 lines (67 loc) · 1.41 KB
/
ch-1.pl
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/perl
# https://perlweeklychallenge.org/blog/perl-weekly-challenge-035/
# dot: 1
# dash: 111
# intra-character gap: 0
# character gap: 000
# word gap: 0000000
use strict;
use warnings;
use v5.10;
my %morse = (
a => '10111',
b => '111010101',
c => '11101011101',
d => '1110101',
e => '1',
f => '101011101',
g => '111011101',
h => '1010101',
i => '101',
j => '1011101110111',
k => '111010111',
l => '101110101',
m => '1110111',
n => '11101',
o => '11101110111',
p => '10111011101',
q => '1110111010111',
r => '1011101',
s => '101010',
t => '111',
u => '1010111',
v => '101010111',
w => '101110111',
x => '11101010111',
y => '1110101110111',
z => '11101110101',
0 => '1110111011101110111',
1 => '10111011101110111',
2 => '101011101110111',
3 => '1010101110111',
4 => '10101010111',
5 => '101010101',
6 => '11101010101',
7 => '1110111010101',
8 => '111011101110101',
9 => '11101110111011101',
' ' => '0000000',
);
my $string = shift;
my @items = split //, $string;
my $code = '';
foreach ( @items ) {
my $b = $morse{lc($_)};
my $s = $b;
$s =~ s/111/—/g;
$s =~ s/1/•/g;
$s =~ s/0/ /g;
#say "$_ : $b \t $s";
say $s;
#print "000";
$code .= $b;
$code .= '000';
}
$code =~ s/0000000000/0000000/g;
$code =~ s/000$//;
say $code;