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:

$string = 'ABAA'; substr($string,0,2)++;
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.
--

($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;

In reply to Outliner Algorithm Ideas? by Cody Pendant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.