in reply to How to identify a number datatype in a string?
USe an eval, it's correct (by definition) and avoids possible errors
my @numbers = ( '1', '2', '10', '1.2', '1e2', '1.02e2', '1.02e-2', 'e-2', 'er', 'et', '0er' ); foreach my $number (@numbers) { my $test = $number; eval { $test +=0; }; if ( $@ ) { print "$number isn't a number \n"; } }
{QA Editors note: This solution doesn't work as described. See Re: Answer: How to identify a number datatype in a string? for more explanation.}
Edited by davido: Repaired <code> tags, reformatted code. Added editorial note to clarify why this example is broken.
--
Anthony Staines
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Answer: How to identify a number datatype in a string?
by hossman (Prior) on May 30, 2003 at 06:31 UTC | |
by parv (Parson) on May 30, 2003 at 07:05 UTC | |
by hossman (Prior) on May 30, 2003 at 22:19 UTC | |
by parv (Parson) on May 31, 2003 at 07:55 UTC |