Advertisement
Guest User

Untitled

a guest
Jan 31st, 2018
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1.  
  2. #!/usr/bin/perl
  3.  
  4.  
  5. @MORSE_VALUES = (".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-",
  6. "...-", ".--", "-..-", "-.--", "--..", "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.");
  7.  
  8. #$morse_message = "-.--....--.-.------.----....-...----------.-.-.--.--....----....--..-.-.-.-.";
  9. #$morse_message = ".-.-.-.-..--....----....--.--.-.-.----------...-....----.------.-.--....--.-";
  10. #$morse_message = "-.-.-.-.--..----....----..-..-.-.-..........---.----....-......-.-..----..-.";
  11. $morse_message = ".-..----..-.-......-....----.---..........-.-.-..-..----....----..--.-.-.-.-";
  12.  
  13.  
  14. open(WORDS, "words");
  15. @words = <WORDS>;
  16. close(WORDS);
  17.  
  18. chomp(@words);
  19.  
  20. @words = (@words);
  21.  
  22. foreach $w (@words) {
  23. $w = uc($w);
  24.  
  25. foreach $x (@words){
  26. $x = uc($x);
  27.  
  28. foreach $y (@words){
  29. $y = uc($y);
  30.  
  31.  
  32. $mw = convertToMorse($w.$x.$y);
  33.  
  34.  
  35. if (index($morse_message, $mw) != -1) {
  36. print "$mw "."$w "."$x "."$y\n";
  37. }
  38. }
  39. }
  40. }
  41.  
  42. sub convertToMorse {
  43. local($str) = @_;
  44.  
  45. $morse = "";
  46.  
  47. for($i=0;$i<length($str);$i++) {
  48. $ascii = ord(substr($str, $i, 1));
  49.  
  50. if ($ascii > 64 && $ascii < 91) {
  51. $morse .= $MORSE_VALUES[$ascii - 65];
  52. }
  53. elsif ($ascii > 47 && $ascii < 58) {
  54. $morse .= $MORSE_VALUES[$ascii - 48 + 26];
  55. }
  56. }
  57.  
  58. return $morse;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement