How to make script very interactive, Script purpose, Get user entered number and find mod, if it is 1 than say "good " and exit the script. if it returns 0, Than ask user to enter odd number,

Validation: 1. accept only numbers, no character,no decimal,no special characters.
2. do not end the script until user has entered the odd number,

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 goes exit mode. and need to execute script again. How make following code very interactive.

$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; }
Thank to all,

finally i completed the script, here i am pasting my updated current script, Let me know if you found any bug in this code,

if ($ARGV[0] != "") { $user_ip = $ARGV[0]; }elsif (($ARGV[0] =~ /\D/ ) || ($ARGV[0] eq "") ){ print "Enter odd number only: "; $user_ip = <STDIN>; }else{ $user_ip = <STDIN>; } do{ #get mod value, if mod_off is 1 then entered number is odd otherwi +se 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 = <STDIN>; } }until($mod_off == 1); print "Good odd number ${user_ip}"; __END__

In reply to reprompt user input, until validation pass by ganeshfriends

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.