I agree with the other commenter. HTML::Template would be ideal for your situation. Additionally this allow you to abstract the HTML from your perl code and focus on the perl in your perl scripts. IMHO it is more readable to have your data in separate files.

Something like this:

#!/usr/bin/perl use strict; use warnings; my $TEMPLATE_PATH = "/some/path/"; my $template_name = "data.tmpl" my $tmpl = new HTML::Template( path => [ "$TEMPLATE_PATH", ], filename => "$template_name", die_on_bad_params => 0, ); $tmpl->params( data1 => 'true', ); open my $OUTPUT, '>', \my $output; print $OUTPUT $tmpl->output(); close $OUTPUT; print $string, "\n";

tmplate1.tmpl:

<tmple_if name'data1'> <table width="100%" border="0" bgcolor="#ffffff" cellpadding="0" +cellspacing="0"> <tr> <td colspan="2">&nbsp;</td> </tr> <tr> <td width="60%">All Names List from:</td> <td width="40%" align="left"><b>$date</b></td> </tr> <tr> <td width="100%" colspan="2">&nbsp;</td> </tr> </table> </tmpl_if> <tmpl_if name='data2'> <table width="100%" border="0" bgcolor="#ffffff" cellpadding="0" cel +lspacing="2"> <tr> <td><b>Name</b></td> <td><b>Address</b></td> <td><b>Phone</b></td> <td><b>Email</b></td> <td><b>$location</b></td> </tr> <tr> <td colspan="5">&nbsp;</td> </tr> </tmpl_it>

You can obviously tailor this more to specifically suit your needs.


In reply to Re: How to use __DATA__ efficiently, help! by PyrexKidd
in thread How to use __DATA__ efficiently, help! 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.