in reply to validate if output of command is numeric or not

The try of mathematics is nice, but flames your brain. You may much faster through using regex "\d+". Please note by this time, that "eq" is not the same than "==" inside of perl!
sub check { my $value=""; if ($_[0]=~ m/\d+/) { $value=$_[0]; print qq~$_[0] is numeric\n~; } el +se { $value=""; print qq~$_[0] is not numeric\n~; } return($value); } my $in=0815; my $out=&check($in); # have phun!

Replies are listed 'Best First'.
Re^2: validate if output of command is numeric or not
by worik (Sexton) on Feb 28, 2016 at 22:42 UTC

    Again.

    sub _isNumeric($){ my $t = shift; defined($t) or confess; no warnings; my $a = $t; $a+=0; return $a eq $t; }

    This should be built in! Doing $a+=0 issues a warning. Unless you a a very careless programmer your code must issue no warnings for valid input. So if you are testing if input is numeric (where it may or may not be, both cases valid) then you have to jump through hoops like this.

    That code above may not work for all cases but it is enough for my purposes.

    Yet another reason to hate Perl. Fix it Larry!

      Your _isNumeric functions nearly the same as Scalar::Util's looks_like_number, mentioned by the other anon elsewhere in this thread. Scalar::Util is a core module, and exposes Perl's internal looks_like_number function, so it pretty much is built in, and your _isNumeric is just using it in a kind of roundabout way. Sorry, but this is a hoop you've built for yourself!