in reply to Suppressing Warning/Error messages

The best thing would be to simply check that $SRVCH conforms to what you expect, that is, a sequence of only digits, before doing the numerical checks:

if( ($SRVCH =~ /\D/) # a non-digit || ($SRVCH > 22) # or greater 22 ||($SRVCH < 1) # or smaller than 1 ||($SRVCH =~ /(\s+)/) # or empty string (but see above) ||($SRVCH =~ /[a-zA-Z]/) # or a to z ){ ...

Also, there is no need to shell out to sleep, because Perl has sleep as a built-in function. See also Time::HiRes if you need sub-second sleep.

Replies are listed 'Best First'.
Re^2: Suppressing Warning/Error messages
by intoperl (Acolyte) on Aug 27, 2015 at 10:29 UTC

    Hi Corion - Thanks for reply. The input i am expecting is definitely Numeric. But what i am trying to achieve here is, if end user happens to choose a BAD choice(which could be anything else but a number), The message displayed should be simply "BAD Choice". I dont need Perl to Err in its way. How can that be achieved ?

      Restructure your if statement as I showed.

      Also, consider reading warnings as it shows how to suppress warnings. But in my opinion, it's much better to structure your code such that it recognizes bad input without raising warnings by, in your example, checking first whether something looks like a number before going on and checking whether it's larger than 22.

        Thanks, working fine as expected !