![]() |
|
Do you know where your variables are? | |
PerlMonks |
Re: Help with Numbers..Pleaseby perlguy (Deacon) |
on Apr 24, 2003 at 14:45 UTC ( [id://252911]=note: print w/replies, xml ) | Need Help?? |
Update: Abigail-II's point is well taken on posting incorrect code. Strike this one and don't bother. I found the problem case after I had already posted. Appologies. Update 2: This following regex should work better, and won't fail in the test cases. The same number of digits will be in the output, unless all 9s are in the string, in which case it will just add 1 digit to the front of the string to accomodate. Again, just an exercise.
Back to the original post: Here is a regular expression way to do it:
It has a flaw: if all the numbers are 9, it will drop the last nine and add a 10, so probably not something you would want to use in production code. But the other test cases that I worked with were fine. It was more of an exercise than anything.
In Section
Seekers of Perl Wisdom
|
|