KPeter0314 has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: condense list of numbers to ranges
by Kanji (Parson) on Jan 28, 2003 at 22:57 UTC | |
by KPeter0314 (Deacon) on Jan 28, 2003 at 23:04 UTC | |
|
Re: condense list of numbers to ranges
by Gilimanjaro (Hermit) on Jan 28, 2003 at 23:29 UTC | |
|
Re: condense list of numbers to ranges
by cees (Curate) on Jan 29, 2003 at 04:15 UTC | |
|
Re: condense list of numbers to ranges
by shotgunefx (Parson) on Jan 29, 2003 at 09:08 UTC |