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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to