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.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.
Thank to all,$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; }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |