Well, I can think of quite a few meanings of "is an integer".
sub isUV { my( $i )= @_; return isIntVal($i) && $i == (0|$i); }
sub isNVint { my( $i )= @_; return isIntVal($i) && $i == int($i); }
sub isInt { my( $i )= @_; return $i =~ /^-?\d+\z/; }
But (update) that doesn't cover "1.2e4", for example, so you can also use (updated):sub isIntVal { my( $i )= @_; return $i =~ /^\s*[-+]?\d+\s*$/; }
sub isIntVal2 { my( $i )= @_; my $warn= 0; { local( $^W )= 1; # my $warn= 0; local( $SIG{__WARN__} )= sub { $warn++ }; $i= 0+$i; } return ! $warn && int($i) == $i; }
I really think that the best solution involves making the looks_like_number() C subroutine that Perl itself uses available to scripts.
- tye (but my friends call me "Tye")In reply to (tye)Re: Integer detection concept
by tye
in thread Integer detection concept
by boo_radley
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |