is there isnumber() function in perl?

is there isnumber() function in perl?

am 25.08.2005 03:22:18 von Jayvee Vibar

Hello,

Is there an IsNumber() function in perl? I'm looking for a way to determine
of a given $variable is numeric or not. Thanks.



--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org

Re: is there isnumber() function in perl?

am 25.08.2005 10:52:15 von hot flame

Use regex..
($variable =3D~ /^\d+$/)?1:0;

On 8/25/05, Jayvee Vibar wrote:
> Hello,
>=20
> Is there an IsNumber() function in perl? I'm looking for a way to determi=
ne
> of a given $variable is numeric or not. Thanks.
>=20
>=20
>=20
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>
>=20
>=20
>

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org

Re: is there isnumber() function in perl?

am 25.08.2005 11:08:08 von Xavier Noria

On Aug 25, 2005, at 3:22, Jayvee Vibar wrote:

> Is there an IsNumber() function in perl? I'm looking for a way to
> determine
> of a given $variable is numeric or not. Thanks.

If you need to know whether it looks like a number there are a few
ways, see

perldoc -q determine

If on the other hand what you need is a way to know whether the
underlying type is really numeric (for instance because you are going
to use it as operand of & on variables that might come as strings
("&" has a dual nature)) then normally one just enforces it explicitly:

sub subroutine_whose_args_are_integers_but_might_come_as_strings {
my ($x, $y) = @_;
$x = 0 + $x; # ensure $x has underlying integer type
$y = 0 + $y; # ensure $y has underlying integer type
my $z = $x & $y; # safe, & acting as bitwise AND for sure
# ...
}

-- fxn



--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org

RE: is there isnumber() function in perl?

am 25.08.2005 11:11:20 von cclarkson

Jayvee Vibar wrote:

: Is there an IsNumber() function in perl? I'm looking for a way to
: determine of a given $variable is numeric or not. Thanks.

Read perlfaq4: "How do I determine whether a scalar is a
number/whole/integer/float?"


HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org