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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (9)
As of 2024-04-19 16:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found