I made small sub to generate the part of the HTML, a navigation bar to be exact, for a project I'm working on and I would like people to comment on it so I can learn from my mistakes and pick a few good pointer along the way.

Thanks!


This sub works by having a hash and an array passed to it. The hash is in a format Name => 'Link' were the Name is the part that shown in the html and the link this the URL that the name set to. If a link is set to '' it will not be displayed as a link. The array is to set the order of the hash is displayed in. The Array can be omitted in which case the Hash will be displayed in random order.

Here is the code,
sub NavB { my %Links = %{+shift}; my @LinkOrder = @{+shift}; my ($Trn, $TL); if (@LinkOrder) { for ( $TL=0; $TL <= $#LinkOrder; $TL++ ) { if ($Trn) { $Trn .= " -> "; } if ($Links{$LinkOrder[$TL]}) { $Trn .= "<a href=\"$Links{$LinkOrder[$TL]}\" target=\"_self\"> <font size=4 face=\"Arial, Helvetica, sans-serif\" color=6666cc>$Li +nkOrder[$TL]</font><\/a>"; } else { $Trn .= "$LinkOrder[$TL]"; } } } else { foreach $TL (sort(keys(%Links))) { if ($Trn) { $Trn .= " -> "; } if ($Links{$TL}) { $Trn .= "<a href=\"$Links{$TL}\" target=\"_self\"> <font size=4 face=\"Arial, Helvetica, sans-serif\" color=6666cc>$TL +</font><\/a>"; } else { $Trn .= $TL; } } } return "\n<font size=4 face=\"Arial, Helvetica, sans-serif\" color=666 +6cc>$Trn</font>\n"; }


------
The Price of Freedom is Eternal Vigilance

In reply to Review this HTML-generating code by SilverB1rd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.