Gossamer Forum
Home : General : Perl Programming :

Help.. Easy Question... IS NUMERIC?

Quote Reply
Help.. Easy Question... IS NUMERIC?
Hello>

I'm sorry, I'm not really a Pearl programmer so I need some basic help from those of you who are.

What is the equivalent to an "IS NUMERIC" function used in Visual Basic?

Basically trying to write a simple Pearl selection statement.

Something like...


IF intX IS NUMERIC Then

Do Something

Else

Do Something Else

End IF


How would you say this in Pearl?

Thanks in advance.
Quote Reply
Re: [boats02] Help.. Easy Question... IS NUMERIC? In reply to
Pearl = Perl

if ($var =~ /^\d+$/) {
Quote Reply
Re: [boats02] Help.. Easy Question... IS NUMERIC? In reply to
This question is answered in the Perl FAQ:

How can I tell if a string is a number?


- wil
Quote Reply
Re: [boats02] Help.. Easy Question... IS NUMERIC? In reply to
natural number

/^\d+$/;

an integer

/^-?\d+$/;
/^[+-]?\d+$/;

decimal number

/^-?\d+\.?\d*$/;
/^-?(?:\d+(?:\.\d*)?|\.\d+)$/;

C float

/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/;
Quote Reply
Re: [perl-x] Help.. Easy Question... IS NUMERIC? In reply to
Is there an echo in this forum? Wink
Quote Reply
Re: [Paul] Help.. Easy Question... IS NUMERIC? In reply to
Is there an echo in this forum? Wink

- wil