Dear Monks
in my perl script, I am running few commands which result 0 or < 0 which will be later used for an arithmetic calculation.
but in some cases command may throw error and arithmetic calculation may give an result which is not expected.
so I would like to validate if return output from command is numeric or not.
I see many people recommended if section in below code.
use warnings; my $cmd = "cmd"; my $value = qx($cmd); my $cmd1 = "cmd1"; my $value1 = qx($cmd1); if (($value+0) eq $value) { print $value . " is numeric"; } else { print $value . " is not numeric"; } if (($value1+0) eq $value1) { print $value1 . " is numeric"; } else { print $value1 . " is not numeric"; } my $total = $value + $value1; print $total; // this gives me total of two values.
I tried to use the same but always result is not numeric which it could be but then i would expect warning while performing the arithmetic operation but i get correct result there so i believe $value is numeric but validation code has some problem.
any pointers?
In reply to validate if output of command is numeric or not by kaka_2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |