in reply to Integer detection concept
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")
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (tye)Re: Integer detection concept
by relax99 (Monk) on Dec 13, 2002 at 15:41 UTC | |
by tye (Sage) on Dec 13, 2002 at 16:10 UTC | |
by dragonchild (Archbishop) on Jan 19, 2005 at 16:36 UTC | |
by Tanktalus (Canon) on Jan 19, 2005 at 16:46 UTC | |
by dragonchild (Archbishop) on Jan 19, 2005 at 17:51 UTC | |
by Tanktalus (Canon) on Jan 19, 2005 at 18:00 UTC |