If you're doing it moduleless, why not:
- read all "(marker) associated text" blocks into a hash
- parse hash keys with rules to work out placement
- create new node hash to show parentage
ie
# use this in your rule tests for position
my %structure = (
1 => {qw(a b c d e f g h i etc...)},
2 => {qw(1 2 3 4 5 6 7 8 9 10 11 12 13 etc...)},
3 => {qw(A B C D E F G H I etc...)},
4 => {qw(i ii iii iv v vi vii viii ix x xi etc...)}
);
my %legalese; # hash to store text/markers
my $key = 2; # key marker to keep order ('1' is tree root)
# read into hash
while (s/\((\w+)\)(.*?)(\(\w+\))/$3/s) {
$legalese{$key}{'list_id'} = $1;
$legalese{$key}{'content'} = $2;
$key++;
}
my %node = ( 1 => ''); # node structure tree
# initialise with single node
# to denote top of page
# now work on rules for tree depth
my $last_node;
# go through markers in order parsed in
for (sort {$a <=> $b;} keys %legalese) {
# too tired to try to create rule set :)
# but set nodes as follows
$node{$_}{'parent'} = 'whatever parent node is'
# either '1', $last_node, or somewhere in between
# using %structure as your guide
$last_node = $_;
}
The above is in no way final code, but that's the sort of approach I'd take.
Hope that's enough pointers. By knowing what type the previous node was, you can create a valid rule for the next node by asking:
- is it of the child type expected?
- is it of the same type, incremented one?
- is it of parent type, incremented one?
- is it of grandparent type, incremented one?
- if out of structure expected, append to previous node (ie, embedded list)
etc, etc...
cLive ;-)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.