Ick. That's really hard to read through. Everything pretty much looks the same. I also find that using CGI's methods to generate HTML to create messy code and prefer to use a templating module such as HTML::Template. A template something like this should do the trick:
<TMPL_LOOP PHONEBOOK> <tr> <td> <TMPL_IF PIC> <TMPL_IF TYPE_OTHER> <img src="/images/thumb_<TMPL_VAR NAME=PIC>" </TMPL_IF> <a href="<TMPL_VAR NAME=PIC"><TMPL_VAR NAME=NAME></a> <TMPL_ELSE> <TMPL_VAR NAME=NAME> </TMPL_IF> </td> <td><TMPL_VAR NAME=PHONE></td> <td><TMPL_VAR NAME=FAX></td> <td><TMPL_VAR NAME=LOC></td> <td> <TMPL_IF TYPE_C> <TMPL_VAR NAME=CON> <TMPL_ELSE> <a href="mailto:<TMPL_VAR NAME=EMAIL>"><TMPL_VAR NAME=EMAI +L></a> </TMPL_IF> </td> </tr> </TMPL_LOOP>
Then all you have to do is create an LoH (list of hashes) that has your data plus TYPE_C and TYPE_OTHER set and use it like:
my $t = HTML::Template->new; $t->param(PHONEBOOK => \@data); print $t->output;
This has the advantage of seperating out your code and design and allowing somebody else to tweak the output. For more info on HTML::Template see its documentation or using CGI, DBI and HTML::Template (a mini tutorial with example code).

Hope this helps.

gav^


In reply to Re: Simplifying repetitive flow structures by gav^
in thread Simplifying repetitive flow structures by Dogma

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.