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: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).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>"; ...
As always, any and all suggestions welcome.
TIA,
Terrence
In reply to Turning a hash into a line of links by OfficeLinebacker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |