<?xml version="1.0" encoding="windows-1252"?>
<node id="212058" title="Does it look like a number?" created="2002-11-11 14:42:45" updated="2005-08-15 06:26:58">
<type id="1980">
snippet</type>
<author id="87452">
broquaint</author>
<data>
<field name="doctext">
</field>
<field name="snippetdesc">
Ask perl if a given scalar looks like a number (requires &lt;tt&gt;[cpan://Inline::C]&lt;/tt&gt;).
&lt;p/&gt;

Inspired by Slaven Rezic's "Include Perl_looks_like_number in Scalar::Util?" [http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2002-11/msg00035.html|post] to p5p.
&lt;p/&gt;

Hopefully this function, or something very similar to it, should be making it into &lt;tt&gt;[Scalar::Util]&lt;/tt&gt; per the p5p thread.
&lt;p/&gt;

&lt;small&gt;&lt;b&gt;update&lt;/b&gt;: changed the title (was &lt;i&gt;Is it a number?&lt;/i&gt;) as it was a little ambiguous in relation to the code&lt;/small&gt;</field>
<field name="snippetcode">
&lt;CODE&gt;
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);
}
&lt;/CODE&gt;</field>
</data>
</node>
