"And can I just say how useful it is that you can assign to and even increment a substring..."

Amen brother! But have your tried to DEcrement a string?

$ perl -le '$_="ABAA";substr($_,0,2)--;print'
-1AA
Whoops! Need to do some more magic to get that work, because i do believe you will need to decrement your sections when you delete. If you don't need to delete or don't care about moving AE to AD and AD to AC because AC was deleted, then never mind. :)

Here is what i have so far - adding sections is a breeze, but deleting is always tougher. This is by no means a perfect solution, just 'food for thought':

use strict; my $hash = { AA => { AA => {}, AB => {}, AC => { AA => { AA => {}, }, }, }, }; add($hash); add($hash->{AB}); add($hash->{AB}->{AA}); print_me($hash); add($hash); add($hash->{AC}) for (0..5); add($hash->{AC}->{AC}); print_me($hash); remove($hash->{AC},'AC'); print_me($hash); remove($hash,'AB'); print_me($hash); sub add { my $ref = shift; my $new = (sort keys %$ref)[-1]; if ($new) { $ref->{++$new} = {}; } else { $ref->{'AA'} = {}; } } sub remove { my $ref = shift; my $sec = shift; delete $ref->{$sec}; for (sort keys %$ref) { # skip higher section next if ord(substr($_,1,1)) < ord(substr($sec,1,1)); my $new = substr($_,0,1) . chr(ord(substr($_,1,1))-1); my %new = %{$ref->{$_}}; $ref->{$new} = \%new; delete $ref->{$_}; } } sub print_me { my $ref = shift; my $ind = shift || ''; for (sort keys %$ref) { print "$ind$_\n"; print_me($ref->{$_},$ind."\t") if ref $ref->{$_}; } }
Too bad you can't just change the actual name of a key, life would be easier (thanks to Zaxo and stephen for confirming this for me). Any monks that know how to improve my remove subroutine, please share!! Corrections welcome too. :)

Final thoughts - use a relational database! But since this is just for fun and education, i wish you God speed! ;)

UPDATE:
Had some warnings - code fixed to prevent these, text changed to remove mention of them.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: Outliner Algorithm Ideas? by jeffa
in thread 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.