Hi Monks!
A few questions here, first on the code I posted is about which line is more efficient and why the commented one is giving me a uninitialized error:
$data = do { local $/; <DATA> }; #do{$data = $data . $_ } while (<DATA>); #gives a uninitialized value +in concatenation
I would like to use "__DATA__" twice is that possible? Also I need to pass the values of variables ($date - $location) into the html inside the "__DATA__", any suggestion? If I run this I am getting the second "__DATA__" printed with the rest of the html code. My goal here is to separate as much as I can the HTML from the Perl.
Here is the code sample I am using:
#!/usr/bin/perl use strict; use warnings; use Date::Calc qw( Today Today_and_Now Date_to_Days Add_Delta_Days Del +ta_Days Decode_Date_US ); my $display=qq(); my $data = qq(); my $date = sprintf "%02d/%02d/%04d", (Date::Calc::Today())[1,2,0]; my $location = "BR"; $display .= qq(\n\nStart Display\n\n); $data = do { local $/; <DATA> }; #do{$data = $data . $_ } while (<DATA>); #gives a uninitialized value +in concatenation $display .= $data; $display .=" <tr> <td>more data</td> </tr> <tr> <td>end of rows</td> </tr> </table>\n"; print $display; __DATA__ <table width="100%" border="0" bgcolor="#ffffff" cellpadding="0" cells +pacing="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> __DATA__ <table width="100%" border="0" bgcolor="#ffffff" cellpadding="0" cells +pacing="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>
Thanks for looking!

In reply to 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.