Advertisement
Guest User

Perl implementation of FizzBuzz "test code"

a guest
Apr 15th, 2010
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.99 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2.  
  3.  
  4.  
  5.  
  6. system('clear');
  7.  
  8.  
  9.  
  10.  
  11. &mainSubRoutineBlock;
  12.  
  13.  
  14. sub mainSubRoutineBlock
  15.  
  16. {
  17. &setupNumbers;
  18.  
  19. # &otherVariables;
  20.  
  21. &mainCalculation;
  22.  
  23. #  printf "$counter\n";
  24. #  $counter = ++$counter;
  25. #  printf "$counter\n";
  26. #  printf ($counter % $fizzNum);
  27.  
  28.  
  29. &terminateScript;
  30. }
  31.  
  32.  
  33.  
  34. sub setupNumbers
  35. {
  36. $fizzNum = 3;
  37. $buzzNum = 5;
  38. $newlineNum = 10;
  39. $counter = 1;
  40. }
  41.  
  42. # sub otherVariables
  43. # {
  44. # if
  45. # }
  46.  
  47. sub mainCalculation
  48. {
  49.  
  50.  
  51.     printf "\n\n\n\n\n\n";
  52.  
  53.  
  54.     while ($counter != 101)
  55.     {
  56.     if (($counter % $fizzNum) == 0) {printf 'Fizz';}
  57.     if (($counter % $buzzNum) == 0) {printf 'Buzz';}
  58.     if (($counter % $fizzNum != 0) && ($counter % $buzzNum != 0)) {
  59.         printf "$counter";
  60.         }
  61.  
  62.     printf ', ';
  63.     if (($counter % $newlineNum) == 0) {printf "\n";}
  64.  
  65.     $counter = ++$counter;
  66.     }
  67.  
  68. }
  69.  
  70. sub terminateScript
  71. {
  72.     # tell the user what is
  73.     # going on.. it is done
  74.  
  75.     printf "\n\n\n".'The test script has terminated.'."\n\n";
  76.     exit;
  77. }
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. #EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement