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

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!

Replies are listed 'Best First'.
Re^3: validate if output of command is numeric or not
by Anonymous Monk on Feb 29, 2016 at 19:01 UTC

    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!