Try this simple code : 

        if ($x+0 != 0 or $x =~ /^t/i ) { return 1; } else { return 0; }



-----Message d'origine-----
De : [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] De la part de
Lyle Kopnicky
Envoyé : mercredi 29 juin 2005 23:53
À : perl-win32-users
Objet : Test if a string is a number?

Hi folks,

I have a seemingly simple problem, but I can't find a satisfying solution.
I have a function which tests to see if a value represents what I want to
call "true".  Here's a simplified version:

    if ($val =~ /true/i || $val =~ /t/i || $val != 0) { return 1; } else {
return 0; }

The text might be numeric or not.  If it is numeric, I want to accept
anything but zero as true.  But, if I run this on a textual non-true value,
such as "false", I get:

  Argument "false" isn't numeric in numeric ne (!=) at ...

The code works, but I don't want to get the warning (I'm using 'warnings').
So, how can I test to see if it's a numeric value, before I try to use it as
one?  I tried using int() to convert it, but that gives the same warning.

Any ideas?  Thanks.

--
Lyle Kopnicky
Software Project Engineer
Veicon Technology, Inc.

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to