| Subject: | Regular expression: How to determine wether entry is a number? |
|---|---|
| From: | janhorstmann@xxxxxx (Jan-Henrik) |
| Date: | Tue, 29 Jul 2008 05:46:09 -0700 (PDT) |
| Newsgroups: | perl.beginners |
Dear Group,
I'm new to Perl and I have a simple question:
I ask for the entry of a number vie <STDIN>:
----------------------------------------
#!/usr/bin/perl -w
use strict;
my $foo;
print "Enter number: ";
$foo = <STDIN>;
comp($foo);
----------------------------------------
Now I would like to check wether the user really entered a number and
not letters. What would a check like that look like? A regular
expression like this:
----------------------------------------
unless ($foo =~ /[a-zA-Z\D+][^.][\D*]/ {...};
----------------------------------------
Is there an easier or more beautiful way?
Also, how would I substract just a number from a string? Searched the
net for an example but didn't succeed, so sorry for asking a question
like that...
Many thanks for your help!
Kind regards,
Jan-Henrik
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Problem related to ZGV installation, Sanket Vaidya |
|---|---|
| Next by Date: | Question about lwp-rget, Bdy |
| Previous by Thread: | Problem related to ZGV installation, Sanket Vaidya |
| Next by Thread: | Re: Regular expression: How to determine wether entry is a number?, Paul Lalli |
| Indexes: | [Date] [Thread] [Top] [All Lists] |