Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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. :)


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2020-05-27 08:50 GMT
Find Nodes?
    Voting Booth?
    If programming languages were movie genres, Perl would be:

    Results (153 votes). Check out past polls.