Keep It Simple, Stupid | |
PerlMonks |
Outliner Algorithm Ideas?by Cody Pendant (Prior) |
on May 10, 2002 at 01:58 UTC ( [id://165573]=perlquestion: print w/replies, xml ) | Need Help?? |
Cody Pendant has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monks,
I've been working on an outliner idea, a cgi-based way of organising documents into sections, subsections and so on. (Note: this is not a work project, just a good way to get myself involved in some interesting perl code, so I'm not looking for a magic bullet or a module, I want to ask for your thoughts) Here's my idea: the sections, (using a tied hash) will be "numbered" using the "Latin" or "alphadeximal" format I was asking about in another thread. Does AA..ZZ have a name? So the first section would be section AA, the second section, section AB. If AA has sub-sections, they are AAAA, AAAB, AAAC and so on. If they in turn have subsections, they are AAAAAA, AAAAAB, and so on. This has the advantage that you can sort all sections into their right order, that you can determine the level by length, gives you unlimited sub-levels and a large number of sections before you run out of "digits". I figured this system would be easier than using numbers for those reasons. You can also get all the contents of section AA by grepping the fact that they begin "AA" and so on. So, the next subroutine I need to write, having got display out of the way, is a renumbering routine for when a section is deleted or inserted. If I insert a section after AA, that's easy, because it's top level. A new section after AA is section AB, so everything AB and after in alphabetical order, gets its first two chars incremented by one. The old AB becomes AC and so on. (And can I just say how useful it is that you can assign to and even increment a substring: produces 'ACAA') Now I realise I've got to figure out the algorithm that will push a sub-section, and all its sub-subsections, down one level. I've just been staring at it too long. I've got as far as "sections which begin with the character string, or a character string after that character string in alpha order, are of equal or greater length, and come after it in alpha order" -- will a "@need_updating = grep {conditions} keys(%hash)" for those conditions produce the right list of the affected sections?
Any thoughts gratefully received.
Back to
Seekers of Perl Wisdom
|
|