On Jul 23, Mads N. Vestergaard said:
I'm trying to check weather a variable is an integer, i have tried the
following:
use Math::BigRat;
my $x = 42;
print "$x is an integer\n" if $x->is_int();
Using Math::BigRat doesn't automatically make numbers into objects. You'd
have to say
my $x = Math::BigRat->new(42);
in order to call the is_int() method. But there's no need to go through
those hoops.
Depending on what your definition of an integer is, you can probably just
do:
if ($x eq int($x)) {
# it's an integer
}
This will fail if $x is something like '00' or '1e0'.
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>