in reply to Re: reprompt user input, until validation pass
in thread reprompt user input, until validation pass

$ip_no = $ARGV[0]; chomp($ip_no); print "$ip_no\n"; $flag=0; while(!$flag) { if($ip_no =~ /\D/ || $ip_no=~ //) { print "enter number\n"; $ip_no=<STDIN>; chomp($ip_no); } else { if ($ip_no%2 ==0) { print "well done bye bye\n"; $flag=1; } else { print "u r expected to enter an odd number\n"; $ip_no=<STDIN>; chomp($ip_no); } } }

Replies are listed 'Best First'.
Re^3: reprompt user input, until validation pass
by jwkrahn (Abbot) on Oct 17, 2011 at 10:45 UTC
    if($ip_no =~ /\D/ || $ip_no=~ //)

    That is the same as saying:

    if($ip_no =~ /\D/ || $ip_no=~ /\D/)

    Because an empty match operator uses the last successfully matched regular expression.

      replace
      -- if($ip_no =~ /\D/ || $ip_no=~ //) ++ if($ip_no =~ /\D/)
Re^3: reprompt user input, until validation pass
by ganeshfriends (Initiate) on Oct 17, 2011 at 09:27 UTC
    snippet keep on asking enter number, not continuing further, even i tried to pass argument while executing script.