in reply to Outliner Algorithm Ideas?
Amen brother! But have your tried to DEcrement a string?
$ perl -le '$_="ABAA";substr($_,0,2)--;print' -1AAWhoops! 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':
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. :)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->{$_}; } }
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)
|
|---|