Greetings, esteemed monks!

I think this is something that might lend itself to `map,` perhaps in conjunction with `join,` though I am not very comfortable with `map.` This code is for a CGI script. Basically, I have a hash, the keys of which are part of the text to be displayed for each link, and the values of which are the URLs. The URLs do change every once in a blue moon, and entries may be added or subtracted (also infrequently), and I'd like to keep that information in a variable and generate the list of links programmatically. Here's what I have so far; note the leading space in the first key, for sorting purposes:
use strict; use warnings; use CGI qw/:all *table'/; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); ... my %sections=(" DMA"=>'dma',FST=>'dma/fst',MRA=>'dma/mra',BKS=>'bks',M +SU=>'dma/msu',FMA=>'dma/fma',FOMC=>'dma/FOMC'); ... print "<h3 align='center'>"; foreach my $s (sort keys(%sections)){ print a({-href => "/$sections{$s}"}, "$s HOME")," |"; } print "</h3>"; ...
Clearly, I have one extra " |" after the last link, which I can fix, but I'm a junkie for "elegant" solutions, thus this node. Unfortunately, since both text and URL change, I don't believe I can use "The Distributive Property of HTML Shortcuts," which I have used to great advantage and with great glee in the past (and indeed in other parts of the program excerpted above).

As always, any and all suggestions welcome.

TIA,
Terrence


I like computer programming because it's like Legos for the mind.

In reply to Turning a hash into a line of links by OfficeLinebacker

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.