Displaying Tags In Perl Using Your Own Code

There are various ways to display a tag cloud. I've chosen a style that closely resembles the tag clouds on Flickr. Here is the HTML for a very small tag cloud, so you can see how it is structured:

<div class="cdiv">
<p class="cbox">
<a href="link1" style="font-size:23px;">tag1</a>
<a href="link2" style="font-size:18px;">tag3</a>
<a href="link3" style="font-size:13px;">tag3</a></p>
</div>

Each word or tag is associated with the style division class cdiv (which is defined in the CSS style file), and the font size is given explicitly for each tag.

These days, it is fashionable to separate style from structure, and keep all stylisticinformation in the CSS file. The tag clouds produced by HTML::TagCloudaccomplish this goal by eliminating the explicit font-size references and using a setof individual styles (tagcloud1, tagcloud2, tagcloud3, and so on), onefor each font size. While the basic idea of separating style from structure isdesirable, this particular use strikes me as silly, since the separate classes arefunctioning as implicit font-size directives. It reduces clarity in the HTML codeand makes the CSS code needlessly complex.

Since we have full control over the code that generates the tag cloud, there is littleneed to use CSS to modify the range of font sizes—instead, we will control thisdetail through scripting.

For the tag clouds in this article, I am putting the font-size directive in the tagcloud code itself, and using a shorter CSS ...

Get Building Tag Clouds in Perl and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.