Number means a lot of things to a lot of people. One generally tricky bit to consider is scientific notation, i.e.
"1.0e1". Fortunately, Perl is smarter than your average third-grader. If the unnecessary bit is only at the end of your string, you can simply use
0+ (the venus operator I think) to numify the result, and let Perl do the heavy lifting:
my @array = (" 321abc ", "100%", "20 lbs.");
no warnings "numeric";
print(0+$_,"\n") for @array;
If you have leading chaff, you can run it through a substitution to strip that first:
my @array = (" 321abc ", "100%", "20 lbs.", "words20", "**39.99.99**
+");
no warnings "numeric";
for (@array) {
s/^[^0-9.-]+//;
print(0+$_,"\n");
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.