Advertisement
Guest User

Error Checking

a guest
Mar 22nd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.74 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use Scalar::Util qw(looks_like_number);
  6.  
  7.  
  8. #*************TEST VALUES*************
  9.  
  10.  
  11.  
  12.  
  13.  
  14. print "Enter a type (0 - 4): ";
  15. my $usrInput = <STDIN>;
  16. chomp $usrInput;
  17. errorCheck($usrInput, "Type");
  18.  
  19. print "Enter a geo code (1-48): ";
  20. $usrInput = <STDIN>;
  21. chomp $usrInput;
  22. errorCheck($usrInput, "GeoCode");
  23.  
  24. print "Enter a valid violation code: ";
  25. $usrInput = <STDIN>;
  26. chomp $usrInput;
  27. errorCheck($usrInput, "VioCode");
  28.  
  29. print "Enter a number from 1 - 14: ";
  30. $usrInput = <STDIN>;
  31. chomp $usrInput;
  32. errorCheck($usrInput, "StaCode");
  33.  
  34. print "Enter a province: ";
  35. $usrInput = <STDIN>;
  36. chomp $usrInput;
  37. isProvince($usrInput);
  38.  
  39. print "Enter a city: ";
  40. $usrInput = <STDIN>;
  41. chomp $usrInput;
  42. isCity($usrInput);
  43.  
  44.  
  45. sub errorCheck {
  46.     while (0 == 0) {
  47.       if (looks_like_number($_[0])) {
  48.         if ($_[0] >= 0 && $_[0] <= 4 && $_[1] eq "Type"){       #Type
  49.             return $_[0];
  50.         }
  51.         elsif ($_[0] == 1 && $_[1] eq "Choice1"){                  #Correlation
  52.           return $_[0];
  53.         }
  54.         elsif ($_[0] >= 1 && $_[0] <= 4 && $_[1] eq "Choice2"){    #String
  55.           return $_[0];
  56.         }
  57.         elsif ($_[0] >= 1 && $_[0] <= 3 && $_[1] eq "Choice3"){    #Numerical
  58.           return $_[0];
  59.         }
  60.         elsif ($_[0] >= 1 && $_[0] <= 2 && $_[1] eq "Choice4"){    #Percentage
  61.           return $_[0];
  62.         }
  63.         elsif ($_[0] >= 1 && $_[0] <= 48 && $_[1] eq "GeoCode"){   #Geo Code
  64.           return $_[0];
  65.         }
  66.         elsif ($_[0] >= 1 && $_[0] <= 255 && $_[0] != 25 && $_[0] != 72 && $_[0] != 73 && $_[0] != 217 && $_[0] != 218 && $_[1] eq "VioCode"){
  67.           return $_[0];                                            #Violations
  68.         }
  69.         elsif ($_[0] >= 1 && $_[0] <= 14 && $_[1] eq "StaCode"){   #Statistics
  70.           return $_[0];
  71.         }
  72.       }
  73.  
  74.     print "Invalid input, please reenter: ";
  75.     $_[0] = <STDIN>;
  76.     chomp $_[0];
  77.     }
  78. }
  79.  
  80.  
  81. sub isProvince {
  82.   while (0==0){
  83.     if (looks_like_number($_[0])){
  84.       if ($_[0] == 2 || $_[0] == 4 || $_[0] == 5 || $_[0] == 7 || $_[0] == 9 || $_[0] == 16 || $_[0] == 28 || $_[0] == 30 || $_[0] == 33 || $_[0] == 36 || $_[0] == 40 || $_[0] == 42){
  85.         return $_[0];
  86.       }
  87.     }
  88.  
  89.     print "Invalid input, please reenter: ";
  90.     $_[0] = <STDIN>;
  91.     chomp $_[0];
  92.   }
  93. }
  94.  
  95. sub isCity {
  96.   while (0==0){
  97.     if (looks_like_number($_[0])){
  98.       if ($_[0] >= 3 && $_[0] <= 48 && ($_[0] != 4 || $_[0] != 5 || $_[0] != 7 || $_[0] != 9 || $_[0] != 16 || $_[0] != 28 || $_[0] != 30 || $_[0] != 33 || $_[0] != 36 || $_[0] != 40 || $_[0] != 42)){
  99.         return $_[0];
  100.       }
  101.     }
  102.  
  103.     print "Invalid input, please reenter: ";
  104.     $_[0] = <STDIN>;
  105.     chomp $_[0];
  106.   }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement