more useful options | |
PerlMonks |
(Ovid) Re: Extract numbers in multiple basesby Ovid (Cardinal) |
on Oct 15, 2001 at 03:07 UTC ( [id://118787]=note: print w/replies, xml ) | Need Help?? |
My first pass at this seems to work okay, though I should probably add a few more tests. Though I have regexes to specify formats, I tried to make it fairly simple to maintain, in case specifications change. There's a test at the top of the code. Just add numbers you want to test to the array to see if they pass or fail.
To be perfectly fair, the scientific notation regex is a bit of a hack and needs to be fixed. The code works by checking whether the argument to the sub is valid for one of the regexes specified in the %bases hash. If it's valid for more than one type, then the argument is considered ambiguous. Cheers, Update: Looking at MrNobo1024's code and it seems like I overcoded the heck out of this. Vote for paco! Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In Section
Seekers of Perl Wisdom
|
|