Skip to content

Instantly share code, notes, and snippets.

@tallpeak
Last active September 1, 2023 05:32
Show Gist options
  • Save tallpeak/eb8f20f91ff326631111d9530d2e75fb to your computer and use it in GitHub Desktop.
Save tallpeak/eb8f20f91ff326631111d9530d2e75fb to your computer and use it in GitHub Desktop.
morse code to ascii
# ASCII 32 to 95, where "" means undefined
@morse = (' ', '-.-.--', '.-..-.', '', '...-..-', '', '.-...', '.----.', '-.--.', '-.--.-', '',
'.-.-.', '--..--', '-....-', '.-.-.-', '-..-.', '-----', '.----', '..---', '...--',
'....-', '.....', '-....', '--...', '---..', '----.', '---...', '-.-.-.', '', '-...-',
'', '..--..', '.--.-.', '.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', '..',
'.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.', '...', '-', '..-',
'...-', '.--', '-..-', '-.--', '--..', '', '', '', '', '..--.-');
$ascii = 32;
for $m(@morse) {
$ch = chr($ascii++);
$morseAscii{$m}=$ch;
}
$message = "... --- ...";
# for $w(split(" ",$message)) {
# print($morseAscii{$w});
# }
$message =~ s/([.-]{1,7})/$morseAscii{$1}/g;
$message =~ tr/ //d;
print($message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment