T
Tuxedo
In trying to construct a nested html list with perl I have some questions
what the ideal data structure may be for the specific purpose.
The menu is generated on the fly for each page request. The script lives in
a perl file named menu.pl and the current page that is accessed is known to
the script via a server environment variable accessible in a $current_page
perl variable. The html parts are imported onto individual html pages
through SSI (includes) and all pages are placed at a root level, so there
are no sub-directories or chances of any pages having a same name.
This is a simplified html output of the menu in an unordered list format:
<ul>
<li><a href=1.1.html>Level 1.1</a>
<ul>
<li><a href=2.1.html>Level 2.1</a></li>
<li><a href=2.2.html>Level 2.2</a>
<ul>
<li><a href=3.1.html>Level 3.1</a></li>
<li><a href=3.2.html>Level 3.2</a></li>
</ul>
</li>
<li><a href=2.3.html>Level 2.3</a></li>
</ul>
</li>
</ul>
So there are three levels and the first two levels have nested lists
within. If for example page 3.2.html is accessed, the script should write
out that <li> entry *without* the enclosing <a href=3.2.html>..</a> parts,
as well as add a css-class to that one list item: <li class=current_page>.
The script should know its nearest parent <li> item, so in case of
accessing page 3.2.html, that would be the <li> with the 2.2.html link.
This entry should then have have the css-class: <li class=parent_level_2>.
Additionally, the second nearest parent should be given another css-class,
such as <li class=parent_level_1> (so it may be styled differently).
If the current page is one that does not exist in the menu, although the
menu has been imported on such a page, then no special classes or non-link
formatting is needed for any of the array entries. The html output would
just appear exactly as the above example.
Without the actual link names, I guess the list may be constructed with a
LoL or an AoA, such as:
my @AoA = ('1.1.html',
['2.1.html',
'2.2.html',
['3.1.html',
'3.2.html'],
'2.3.html']);
If so, a parallel AoA's would be needed for the link names to be combined
in a final loop. Or is some other data structure better suited for the
purpose? I.e.: sticking all items together in a nested html list in order
of entry in the perl code, as well as figure out the opening parent <li>
points (if any) in order to apply custom css-classes to relevant <li>'s.
Looking at perldsc, in addition to AoA, alternatives such as HoA, AoH, HoH
as well as some more elaborate data structures exist. I'm not sure what's
best? The maintenance of the link list will involve changing or updating
entries only very occasionally, so it can be done in separate arrays in
case that's better. Anyway, it's not important how, as long as it works...
What is the ideal data structure for the particular hierarchial list
functionality and where the described level specific output can easily be
incorporated?
Many thanks for any advise or general pointers.
Tuxedo
what the ideal data structure may be for the specific purpose.
The menu is generated on the fly for each page request. The script lives in
a perl file named menu.pl and the current page that is accessed is known to
the script via a server environment variable accessible in a $current_page
perl variable. The html parts are imported onto individual html pages
through SSI (includes) and all pages are placed at a root level, so there
are no sub-directories or chances of any pages having a same name.
This is a simplified html output of the menu in an unordered list format:
<ul>
<li><a href=1.1.html>Level 1.1</a>
<ul>
<li><a href=2.1.html>Level 2.1</a></li>
<li><a href=2.2.html>Level 2.2</a>
<ul>
<li><a href=3.1.html>Level 3.1</a></li>
<li><a href=3.2.html>Level 3.2</a></li>
</ul>
</li>
<li><a href=2.3.html>Level 2.3</a></li>
</ul>
</li>
</ul>
So there are three levels and the first two levels have nested lists
within. If for example page 3.2.html is accessed, the script should write
out that <li> entry *without* the enclosing <a href=3.2.html>..</a> parts,
as well as add a css-class to that one list item: <li class=current_page>.
The script should know its nearest parent <li> item, so in case of
accessing page 3.2.html, that would be the <li> with the 2.2.html link.
This entry should then have have the css-class: <li class=parent_level_2>.
Additionally, the second nearest parent should be given another css-class,
such as <li class=parent_level_1> (so it may be styled differently).
If the current page is one that does not exist in the menu, although the
menu has been imported on such a page, then no special classes or non-link
formatting is needed for any of the array entries. The html output would
just appear exactly as the above example.
Without the actual link names, I guess the list may be constructed with a
LoL or an AoA, such as:
my @AoA = ('1.1.html',
['2.1.html',
'2.2.html',
['3.1.html',
'3.2.html'],
'2.3.html']);
If so, a parallel AoA's would be needed for the link names to be combined
in a final loop. Or is some other data structure better suited for the
purpose? I.e.: sticking all items together in a nested html list in order
of entry in the perl code, as well as figure out the opening parent <li>
points (if any) in order to apply custom css-classes to relevant <li>'s.
Looking at perldsc, in addition to AoA, alternatives such as HoA, AoH, HoH
as well as some more elaborate data structures exist. I'm not sure what's
best? The maintenance of the link list will involve changing or updating
entries only very occasionally, so it can be done in separate arrays in
case that's better. Anyway, it's not important how, as long as it works...
What is the ideal data structure for the particular hierarchial list
functionality and where the described level specific output can easily be
incorporated?
Many thanks for any advise or general pointers.
Tuxedo