title: Perl reprompt user input until get exact expected input
body: <p>How to make script very interactive?</p>
  
  <p>Script purpose:<br>
  Get user entered number and find mod via <code>get_mod_val</code> function; if it returns 1 then say "good" and exit the script; if it returns 0, then ask user to enter odd number.</p>
  
  <p>Validation:</p>
  
  <ol>
  <li>accept only numbers, no character, decimal, special characters.</li>
  <li>do not end the script until user has entered the odd number.</li>
  </ol>
  
  <p>The following code works fine; it follows above validation point 1 rules, but it is not very interactive as per our requirement law.  When above rules fails, script exits and we need to execute the script again.</p>
  
  <p>How can we make the following code very interactive?</p>
  
  <pre><code>$ip_no = $ARGV[0];
  if ($ip_no!="") {
  
      $get_mod_op = get_mod_val($ip_no);
      if ($ip_no =~ /\D/){
          print "Entered number only.....";
          exit;
      }else{
          if ($get_mod_op==1) {
              print "Good odd number(${get_mod_op}): ${ip_no} ";
              exit;
          }else{
              print "Good even number(${get_mod_op}): ${ip_no} ";
              exit;
          }
  
      }
  }else{
      print "Enter number.";
      exit;
  }
  </code></pre>
  
  <p>Thank to all, finally i have done the code with your suggestions, Following snippet reached my requirement, review the code and advise for optimization. </p>
  
  <pre><code>if ($ARGV[0] != "") {
      $user_ip = $ARGV[0];
  }elsif (($ARGV[0] =~ /\D/ ) || ($ARGV[0] eq "") ){
       print "Enter odd number only: ";
       $user_ip = &lt;STDIN&gt;;
  }else{
      $user_ip = &lt;STDIN&gt;;
  }
  
  do{ #get mod value, if mod_off is 1 then entered number is odd otherwise ask user to enter the odd number
      $mod_off = find_mod_val($user_ip);
      if (($user_ip == "") || ($user_ip eq "") || ($user_ip eq "") || ($mod_off == 0)) {
          print "Enter odd number only: ";
          $user_ip = &lt;STDIN&gt;;
      }
  }until($mod_off == 1);
  
  print "Good odd number ${user_ip}";
  
  
  
  sub find_mod_val($user_ip){
      return $user_ip%2;
  }
  __END__
  </code></pre>