After looking at ambrus' cool text to morse one-liner this morning:

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_c +ode # # 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 @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] = ','; # Rather than having ',' in the qw() array. # These are the indices where the number of characters increase. my %steps; map( $steps{$_} = 1, qw(1 3 7 15 31) ); my ($step, $fig); for my $idx ( 1 .. $#chars ) { $chars[$idx] =~ s/^~$//g; if ( $steps{$idx} ) { $fig += 32; $step = $fig - $idx; } printf "%08b %s\n", $idx + $step, $chars[$idx-1]; }
Which could also be used as the basis for a Text->Morse / Morse->text convertor.

In reply to Morse Code as binary by serf

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.