Hi, I am looking for comments on an idea, and/or suggestions on how to improve it/replace it with something else. I have some pretty complex stand alone sql, plus some stored procedures, which I execute via perl+DBI. My concerns are regarding how to best handle the output. Most of the time, HTML+CSS reports/email will be produced, but some people will also need the output as comma delimited. My about-to-be-implemented idea consists of the following. Write a module, say SQLData, with subroutines for each query, which will take a parameter to output .csv or ready to be displayed html. i.e.
package @SQLData ... sub css { if needed, define css here, else link to it. this will be mostly used for html emails, given that linking to it will be a pain if it goes outside the company } sub foo { my $bar = shift(@_); my @output; my $sql = ("sql code here") my @array $sql->execute; while (@array = $sql->fetchrow_array) { if ($bar=='csv') { push(@output,"$foo[0],$foo[1]"} } else { push(@output,"<tr><td>$foo[0]</td><td>$foo[1]</td></tr>"); } } $sql->finish(); return @output; }
What do you think? Is this the best way to approach it? Is it even a good way? Thanks.

2005-08-17 Retitled by Arunbear, as per Monastery guidelines
Original title: 'How does this look?'


In reply to Exporting data from database as HTML or CSV by Anonymous Monk

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.