Ask perl if a given scalar looks like a number (requires Inline::C).
Inspired by Slaven Rezic's "Include Perl_looks_like_number in Scalar::Util?" post to p5p.
Hopefully this function, or something very similar to it, should be making it into Scalar::Util per the p5p thread.
update: changed the title (was Is it a number?) as it was a little ambiguous in relation to the code
use Inline C; my $var = shift; print +(isnum($var) ? "is a number" : "not a number"), ": $var", $/; __END__ __C__ int isnum(SV* val) { return Perl_looks_like_number(val); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Is it a number?
by princepawn (Parson) on Nov 11, 2002 at 20:48 UTC | |
by broquaint (Abbot) on Nov 12, 2002 at 00:19 UTC | |
by merlyn (Sage) on Oct 23, 2003 at 14:50 UTC | |
Re: Does it look like a number?
by xdg (Monsignor) on Dec 15, 2004 at 17:16 UTC |
Back to
Cool Uses for Perl