in reply to Integer detection concept

I'd frown on it because this is so much more straightforward:
sub is_int { $_[0] == int $_[0]; }

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re^2: Integer detection concept
by tadman (Prior) on May 15, 2001 at 00:33 UTC
    For regular numbers, this is works, but it also claims 'integerness' for things like '2na' and '4ever'. Would a regexp be a reliable way of catching this, or is there something better?
    sub is_int { ($_[0] =~ /^\-?\d+(?:\.\d+)?(?:e\+\d+)?$/ && $_[0] == int $_[0]); }
Re: Re: Integer detection concept
by boo_radley (Parson) on May 15, 2001 at 00:28 UTC
    I realized this after I pushed 'submit'... I'm a dolt.