Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- @MORSE_VALUES = (".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-",
- "...-", ".--", "-..-", "-.--", "--..", "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.");
- #$morse_message = "-.--....--.-.------.----....-...----------.-.-.--.--....----....--..-.-.-.-.";
- #$morse_message = ".-.-.-.-..--....----....--.--.-.-.----------...-....----.------.-.--....--.-";
- #$morse_message = "-.-.-.-.--..----....----..-..-.-.-..........---.----....-......-.-..----..-.";
- $morse_message = ".-..----..-.-......-....----.---..........-.-.-..-..----....----..--.-.-.-.-";
- open(WORDS, "words");
- @words = <WORDS>;
- close(WORDS);
- chomp(@words);
- @words = (@words);
- foreach $w (@words) {
- $w = uc($w);
- foreach $x (@words){
- $x = uc($x);
- foreach $y (@words){
- $y = uc($y);
- $mw = convertToMorse($w.$x.$y);
- if (index($morse_message, $mw) != -1) {
- print "$mw "."$w "."$x "."$y\n";
- }
- }
- }
- }
- sub convertToMorse {
- local($str) = @_;
- $morse = "";
- for($i=0;$i<length($str);$i++) {
- $ascii = ord(substr($str, $i, 1));
- if ($ascii > 64 && $ascii < 91) {
- $morse .= $MORSE_VALUES[$ascii - 65];
- }
- elsif ($ascii > 47 && $ascii < 58) {
- $morse .= $MORSE_VALUES[$ascii - 48 + 26];
- }
- }
- return $morse;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement