Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Outliner Algorithm Ideas?

by stephen (Priest)
on May 10, 2002 at 02:50 UTC ( #165581=note: print w/ replies, xml ) Need Help??


in reply to Outliner Algorithm Ideas?

I would suggest that you store the items in an arrayref of hashrefs containing arrayrefs containing hashrefs, like so:

# Represents # AA Sections are cool # AB They are extremely cool # ABAA That's right, really cool # ABAB Again, really cool my $sections = [ {content => 'Sections are cool' }, {content => 'They are extremely cool', subsecs => [ { content => "That's right, really cool" +}, { content => "Again, really cool" }, ] } ];
Then, you can print the sections out with something vaguely resembling this
recurse_section( $sections ); sub recurse_section { my ($sections, @vaportrail) = @_; push @vaportrail, 'AA'; foreach my $section (@$sections) { print @vaportrail, " ", $section->{'content'}, "\n"; recurse_section($section->{subsecs}, @vaportrail) if defined $section->{subsecs}; $vaportrail[ $#vaportrail ]++ } }
That way, your model (the section data) doesn't get entangled with the view (what the numbering scheme looks like). Then promoting a section is as easy as a little data manipulation:
# Add a supersection above "They are extremely cool" my $moving_section = $sections->[1]; $sections->[1] = { content => 'And moving sections is easy too!', subs +ecs => [ $moving_section ] }; recurse_section( $sections );

You can tie your hashtable to a subroutine that translates the ABAAAC business to a list of array indices. That I'll leave to you. :)

stephen


Comment on Re: Outliner Algorithm Ideas?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://165581]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (18)
As of 2015-07-01 19:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (16 votes), past polls