daily pastebin goal
55%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2.  
  3. use warnings;
  4. use strict;
  5. use diagnostics;
  6.  
  7. use IO::Handle;
  8.  
  9. sub input_number
  10. {
  11.     print "What is your number? (0-25) ";
  12.     STDOUT->flush();
  13.     my $number = <>;
  14.     chomp($number);
  15.  
  16.     return $number;
  17. }
  18.  
  19. sub check_number
  20. {
  21.     my $number = shift;
  22.  
  23.     if ($number< 0) {
  24.         print {*STDERR}
  25.         "The number can not be less than 0, please try again.\n";
  26.         return 0;
  27.     }
  28.     elsif ($number> 25) {
  29.         print {*STDERR}
  30.         "The number can not be more than 25, please enter your number.\n";
  31.         return 0;
  32.     }
  33.     elsif (($number !~ m{\A\d+\z}) || ($number =~ m{\A0\d})) {
  34.         print {*STDERR} "The number must be an integer.";
  35.         return 0;
  36.     }
  37.     else {
  38.         return 1;
  39.     }
  40. }
  41.  
  42. my $number = input_number();
  43.  
  44. while (! check_number($number))
  45. {
  46.     $number = input_number();
  47. }
  48.  
  49. print "You've chosen $number! Congrats.\n";
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top