Hi Monks, I have a script which needs to insert a line into an html file after a certain point (ie, at the beginning of the html file.) We have a build system that I want take results from and present the most recent results first.
The script looks like: (I've redacted redundant information)
#!/usr/local/bin/perl -w use strict; use Env qw(COMPUTERNAME); use Tie::File; use File::Copy; my(@cvscommits) = ""; my($cvscommits) =""; my($buildresultserver) = "\\\\Cvs3b\\stuff\\"; my($htmloldfile) = "Verification_Builds1.html"; print "Going to server!\n"; chdir $buildresultserver or die "Cannot change to cvs3b $!\n"; print "going to tie the file\n"; tie @cvscommits, 'Tie::File', "$htmloldfile", or die "Cannot open $htm +loldfile $!\n"; for (@cvscommits) { if (/<th>PC Number<\/th><th>Cores<\/th><th>Date<\/th><th>Customer< +\/th><th>Target<\/th><th>C\/O Time<\/th><th>Build Time<\/th><th>Statu +s<\/th><th>Changes from Last Build<\/th><tr>/) { print "Whee found it \n"; $_ .= "<td><a href=\"\\\\$COMPUTERNAME\\$softdev\\$dirtime\"<b +>$COMPUTERNAME</b></a></td><td>$processors</td><td>$dirtime</td><td>$ +cust</td><td>$target</td><td>$cotime</td><td>$buildtime</td><td>$resu +lt</td><tr>@cvscommits</tr>\n"; last; }} untie @cvscommits;
I've been following a previous answer:
http://www.perlmonks.org/?node_id=155567
What I thought the script was going to do
Go to the file on the server and open it into an array
Search for the pattern that begins with <th>PC Number... and then after that line, insert my line <td><a href...
What is actually happening is that the contents of the html get copied repeatedly every time the script is run, so I get two copies of the contents, rather than the 1 line added I thought I was going to get. It finds the <th>PC Number</th> but then tacks the entire contents of the file onto the end of that line.
The html code is simply the following:
<html> <head> <title> BUILD ENVIRONMENT INFORMATION </title> <STYLE type="text/css"> </STYLE> </head> <body><hr> <h2><center> Daily Verification </center></h2> <table border="1"> <tr> <th>PC Number</th><th>Cores</th><th>Date</th><th>Customer</th><th>Targ +et</th><th>C/O Time</th><th>Build Time</th><th>Status</th><th>Changes + from Last Build</th><tr>

And then my script is supposed to add things to the top of the file. Can anyone enlighten me why it's not doing what I thought it would?

In reply to Tie::File insertion problem by Flubb

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.