Skip to content

Instantly share code, notes, and snippets.

@tabletick
Created October 9, 2012 08:50
Show Gist options
  • Save tabletick/3857462 to your computer and use it in GitHub Desktop.
Save tabletick/3857462 to your computer and use it in GitHub Desktop.
Nato Radio Alphabet
#!/usr/bin/perl
# 20120909/JT
# Printing out the radio alphabet
# or translating a string into it.
# http://en.wikipedia.org/wiki/NATO_phonetic_alphabet
use 5.10.1;
use strict;
use warnings;
my %NatoAlphabet = (
'a' => 'Alpha',
'b' => 'Bravo',
'c' => 'Charlie',
'd' => 'Delta',
'e' => 'Echo',
'f' => 'Foxtrott',
'g' => 'Golf',
'h' => 'Hotel',
'i' => 'India',
'j' => 'Juliet',
'k' => 'Kilo',
'l' => 'Lima',
'm' => 'Mike',
'n' => 'November',
'o' => 'Oscar',
'p' => 'Papa',
'q' => 'Quebec',
'r' => 'Romeo',
's' => 'Sierra',
't' => 'Tango',
'u' => 'Uniform',
'v' => 'Victor',
'w' => 'Whiskey',
'x' => 'X-Ray',
'y' => 'Yankee',
'z' => 'Zulu'
);
if ( @ARGV eq 0 ) { # Just printout the alphabet
print "\n";
foreach my $letter ( sort keys %NatoAlphabet ) {
printf( "%10s\t%-10s \n", $letter, $NatoAlphabet{$letter} );
}
print "\n";
}
else { #Translate the string into the alphabet
print "\n\t";
foreach my $letter ( split //, $ARGV[0] ) {
if ( $letter =~ m/\d/ ) {
print $letter;
}
else {
print $NatoAlphabet{ lc($letter) };
}
print ' ';
}
print "\n\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment