intoperl has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I have a code, which apparently working fine but Perl shoots its own error msg and output looks ugly. Pls see the code snippet below :

Print "Enter the Serial No. for Server to check its CPU us +age :"; Print "OR, Press 22 to EXIT ... "; chomp($CHOICE = <STDIN>); print " " ; if(($CHOICE =~ /\s/)||($CHOICE =~ /\D/)||($CHOICE > 22)||($CHO +ICE < 1)) { Print "ERROR : Bad Choice...Try again now.."; system("sleep 1.5"); disp_menu(); } elsif ($CHOICE == 22) { Print "INFO_CODE:22 User Opted to EXI +T, Exiting now..."; exit 22; } else { $SSHSRVR = $SRV{$CHOICE}; Print "Server selected is : $SRV{$CHOICE}"; cpuchk($SSHSRVR);

This Code snippet works fine BUT gives below error, when i press 'return/Enter' Key:

Argument "" isn't numeric in numeric gt (>) at ./cpu_chk.pl line 107, +<STDIN> line 1. --------->Perl Error Message ERROR : Bad Choice...Try again now.. --->My Error Message

Pls help me to suppress the Perl's unwanted warning. Thanks

Replies are listed 'Best First'.
Re: Hiding Perl Error
by Corion (Patriarch) on Sep 15, 2015 at 11:02 UTC

    This is a continuation of Suppressing Warning/Error messages.

    You now are trying to compare the empty string numerically, which to Perl doesn't make much sense so it warns you. You could check that your string is not the empty string before trying a numeric comparison.

      Thats it Corion, You nailed it right. Thanks !!