Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Morse Code Converter

by Octavian (Monk)
on Oct 30, 2000 at 20:16 UTC ( #39106=sourcecode: print w/ replies, xml ) Need Help??

Category: Fun Stuff
Author/Contact Info Octavian
Description: I was bored sitting around the office, and I felt like annoying a co-worker so I decided to write something up real quick that will email him messages in morse code. This code basically just converts whatever you give it as arguments into more code and emails it to the first argument. so you could do a ./convert someperson@wherever.com this is a test of morse code. and it would send someperson the sentence in morse code
#!/usr/local/bin/perl
$who = $ARGV[0];
$who =~ s/\s+$//;
shift(@ARGV);

open(tomail,"|/usr/sbin/sendmail $who");
foreach $line(@ARGV)
{
  $line =~ s/\s+$//;
  $line =~ s/\s+/\^ /g;
  $line =~ tr/[A-Z]/[a-z]/;
  $line =~ s/\./\.\-\.\-\.\- /g;
  $line =~ s/\?/\.\.\-\-\.\. /g;
  $line =~ s/\!/\.\-\-\-\-\. /g;
  $line =~ s/a/\.\- /g;
  $line =~ s/b/\-\.\.\. /g;
  $line =~ s/c/\-\.\-\. /g;
  $line =~ s/d/\-\.\. /g;
  $line =~ s/e/\. /g;
  $line =~ s/f/\.\.\-\. /g;
  $line =~ s/g/\-\-\. /g;
  $line =~ s/h/\.\.\.\. /g;
  $line =~ s/i/\.\. /g;
  $line =~ s/j/\.\-\-\- /g;
  $line =~ s/k/\-\.\- /g;
  $line =~ s/l/\.\-\.\. /g;
  $line =~ s/m/\-\- /g;
  $line =~ s/n/\-\. /g;
  $line =~ s/o/\-\-\- /g;
  $line =~ s/p/\.\-\-\. /g;
  $line =~ s/q/\-\-\.\- /g;
  $line =~ s/r/\.\-\. /g;
  $line =~ s/s/\.\.\. /g;
  $line =~ s/t/\- /g;
  $line =~ s/u/\.\.\- /g;
  $line =~ s/v/\.\.\.\- /g;
  $line =~ s/w/\.\-\- /g;
  $line =~ s/x/\-\.\.\- /g;
  $line =~ s/y/\-\.\-\- /g;
  $line =~ s/z/\-\-\.\. /g;
  $line =~ s/0/\-\-\-\-\- /g;
  $line =~ s/1/\.\-\-\-\- /g;
  $line =~ s/2/\.\.\-\-\- /g;
  $line =~ s/3/\.\.\.\-\- /g;
  $line =~ s/4/\.\.\.\.\- /g;
  $line =~ s/5/\.\.\.\.\. /g;
  $line =~ s/6/\-\.\.\.\. /g;
  $line =~ s/7/\-\-\.\.\. /g;
  $line =~ s/8/\-\-\-\.\. /g;
  $line =~ s/9/\-\-\-\-\. /g;
  $line =~ s/\,/\-\-\.\.\-\- /g;
  print tomail "$line ";
}
print tomail "\n";
close tomail;

Comment on Morse Code Converter
Download Code
RE: Morse Code Converter
by KM (Priest) on Oct 30, 2000 at 20:57 UTC
    Also, check out the Perl version of morse in the PPT here, and demorse here. It would be interesting to see a benchmark of the two ways of converting (above uses s///, and morse uses a map of a hash.)

    Cheers,
    KM

RE: Morse Code Converter
by AgentM (Curate) on Oct 30, 2000 at 21:21 UTC
    If you've got bsdgames on your computter (sic), (fortune, rain, worms, etc.) you've also got morse, which you could have just piped to sendmail...
    AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.
      It's my understanding that 'morse' doesn't have the full Morse character set in it.

      --Chris

      e-mail jcwren
        ok, I wasn't aware of that. before we go off on discussing our current 'morse' version, let's keep in mind that this guy was just wasting some time, so let's not waste ours :-)
        AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://39106]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2014-07-30 02:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls