Of course. If I had to allow for numbers, and not just natural numbers, I'd DTRT: split on comma, and compare with eq.
(Update) Whoops! Of course I meant <=>. Naturally. :-)
sauoq's comments about dealing with whitespace are worthwhile; but the OP's sample data clearly had no whitespace to deal with.
We're building the house of the future together.
| [reply] [d/l] [select] |
I'd DTRT: split on comma, and compare with eq.
Eeek! Compare with eq? So, you really don't want to know whether "1.234e-5" is numerically the same as ".00001234"? Or, for that matter, "1", "1.0", and "1.00" should all be different?
Oh, and should this list: "1.0, 2.0" be considered different than "1.0,2.0" (because you are splitting on commas and not removing space?)
I suspect you just misspoke there with the eq comment.
The way I'd approach this would be to split on /\s*,\s*/ and use numerical comparisons. I'd allow spaces in input because if they weren't, that would probably be the most common input error and it's pretty cheap to avoid—be liberal in what you accept and conservative in what you emit, and all that. The caveats to this approach are that you are limited in precision to what your perl provides and the input format is rigid (even with optional spaces.)
-sauoq
"My two cents aren't worth a dime.";
| [reply] [d/l] [select] |