Alphabetic->morse converter:
perl -wpe 's{[a-z ]}{"% etianmsurwdkgohvf%l%pjbxcyzq"=~/\l$&/;(unpack" +B8",pack"C",@-)=~/0+1(.*)/;($x="$1")=~y/01/.-/;$x}gie'
I have been having a play with the idea of representing morse code in binary and came up with this:
#!/usr/bin/perl
#
# Morse Code as binary
#
# Given this table:
# http://en.wikipedia.org/wiki/Morse_code
# #Alternate_display_of_more_common_characters_for_the_international_code
#
# Building an array padded with ~ (which is not used in Morse)
# this turns the array index into a binary number representing
# the Morse code:
# the first 3 digits are the number of dits and dahs in the letter
# the last 5 digits represent the morse symbol where 0 is . and 1 is _
#
use strict;
use warnings;
my ($val, $fig, $dec);
my @chars = qw(
E T I A N M S U R W D K G O H V F Ü L Ä P J B X C Y Z Q Ö CH 5
4 ~ 3 É ~ Ð 2 ~ È + ~ Þ À ~ 1 6 = / ~ ~ ~ ~ ~ 7 ~ ~ Ñ 8 ~ 9 0 ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ? _ ~ ~ ~ ~ " ~ ~ . ~ ~ ~ ~ @ ~ ~ ~ ' ~ ~
- ~ ~ ~ ~ ~ ~ ~ ~ ; ! ~ () ~ ~ ~ ~ ~ % ~ ~ ~ ~ : ~ ~ ~ ~ ~ ~ ~
);
$chars[113] = ',';
for my $char ( @chars ) {
$char =~ s/~//g;
$val++;
my %steps = (
1 => 1,
3 => 3,
7 => 7,
15 => 15,
31 => 31
);
if ( $steps{$val} ) {
$fig += 32;
$dec = $val;
}
printf "%08b %s\n", $val + $fig - $dec, $char;
}
Which could also be used as the basis for a Text->Morse / Morse->text convertor.
perlmonks.org content © perlmonks.org and serf
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03