in reply to How to use __DATA__ efficiently, help!

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.

Replies are listed 'Best First'.
Re^2: How to use __DATA__ efficiently, help!
by Anonymous Monk on Feb 10, 2011 at 01:43 UTC
    Thank you all, thats the way to go!