A devilishly simple perl programming problem has hit me while trying to output some information to a web page in a condensed form. <as opposed to that amazingly long and uncondensed sentence>
I'm trying to condense a list of numbers e.g. (1 2 3 4 8 9) to a list of ranges (1-4,8,9). As I am reading and creating the data it can be stored in any form but I have chosen an array at this time so the program can walk through the list and it can be sorted if necessary. The actual lists of numbers may be quite a bit longer than the examples so this really would help in display space.
I did find the module Perlbug::Object::Range, but it comes with a LOT of baggage. It also doesn't handle singles nicely. It outputs (1-4,8-9) which is OK, but not what I would like to really see. My install of this module also seems to double up on single last numbers (1 2 3 4 8) becomes (1-4,8-8). I don't know if that is the intended action, but it is definitely not right.
Would any of the monks out there have a module or pre-written code to do this? I have started writing something, but I am still a perl novice and this works out to be a rather complex set of logic. I would rather use a pre-made wheel than carve my own so I can stick to the actual logic of the program and not worry so much about writing the formatting routines. I know it is a little lazy, but don't we all use standard CPAN modules so we can be just a little lazy.
-Kurt
In reply to condense list of numbers to ranges by KPeter0314
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |