Hello masters of knowledge, I have another (probably goofy) question..... I have the following code-
#!C:\strawberry\perl\bin\perl.exe use DBI; use Tie::File; $dbh = DBI->connect('dbi:mysql:Database','username','password') or die "Connection Error: $DBI::errstr\n"; $sql = "select cost, data from table"; $sth = $dbh->prepare($sql); $sth->execute or die "SQL Error: $DBI::errstr\n"; $sitedata="/xampp/cgi-bin/Smartware_LTD_Website/aberKarateCosts.html"; open(DAT,">>$sitedata") || die("Cannot Open File"); print DAT"<div id='costtable'>"; print DAT"<table border='1'>"; print DAT"<tr><th>$sth->{NAME}->[0]</th><th>$sth->{NAME}->[1]</th></tr +>"; while (@row = $sth->fetchrow_array) { print DAT"<tr><td>$row[0]</td><td>$row[1]</td></tr>"; } print DAT"</div>"; close FILE;
The above code opens a file and then writes the table result in html into that file. The file is a html file; therefore solving a previous question which i posted on here about mixing perl with html (for my needs anyway)! The problem I am having is that I only want this table to occur once, but when I run the perl more than once the table appears twice, three times etc. I have tried multiple lines to try and fix this. I want the table to up-date however when new data is added to the database, but each time an up-date occurs the original html table should be removed. please help, I think its just a line or two of code, i just cant crack the egg! Bogglemaster89

In reply to Perl to add a table once and then when run again delete the original table (but not the whole html document)! by bogglemaster89

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.