kaka_2 has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: validate if output of command is numeric or not
by Discipulus (Canon) on Jan 08, 2016 at 08:44 UTC | |
|
Re: validate if output of command is numeric or not (numify)
by Anonymous Monk on Jan 08, 2016 at 08:47 UTC | |
|
Re: validate if output of command is numeric or not
by BillKSmith (Monsignor) on Jan 08, 2016 at 14:03 UTC | |
|
Re: validate if output of command is numeric or not
by Anonymous Monk on Jan 09, 2016 at 09:37 UTC | |
by worik (Sexton) on Feb 28, 2016 at 22:42 UTC | |
by Anonymous Monk on Feb 29, 2016 at 19:01 UTC |