Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append to the specific location of the file

Status
Not open for further replies.

janpickron

Programmer
Joined
Sep 20, 2006
Messages
2
Location
US
Hi Perlians,

I am wondering if it is "doable."

When you post an ad, it usually append at the bottom of the file. However, we would like to put the block of a table in the specific location (right after the <!-- PUT UNDER HERE --> line) of the file. For example:

<html>
<head><title>Post</title></head>
:
:
<body>
</body>
</html>
<!-- PUT UNDER HERE -->

<br>
<table>
<tr><td>Information Three</td></tr>
</table>

<br>
<table>
<tr><td>Information Two</td></tr>
</table>

<br>
<table>
<tr><td>Information One</td></tr>
</table>

Every time we submit a post, we would like this post to go after the line <!-- PUT UNDER HERE --> BUT before the table of Information Three. Is it possible ?

Thanks in advance!
 
I forgot to put the code in my first thread! :-(

open (FILE,"+< $filename");
while (<FILE>)
{
if (/PUT UNDER HERE/)
{
print FILE "<br><table border=0>\n";
print FILE "<TR><td>Information $in(number)</td>\n";
print FILE "</td></tr></table>\n";
}
else
{
print ("Cannot find the PUT UNDER HERE string." );
}
}
close(ADFILE);
 
I saw couple of issues in your HTML formatting.
1) </body></html> closeing right after opening tags.
2) There is an additional </td> in your perl code.

You have not specified where $in(number) is coming from.
Code:
print qq {
<html>
<head><title>Post</title></head>
   :
   :
<body>
} ;
open (FILE,"+< $filename");
while (<FILE>)
{
 if (/PUT UNDER HERE/)
  {
  print FILE "<br><table border=0>";
  print FILE "<TR><td>Information $in(number)</td>\n";
  print FILE "</tr></table>";
  }
  else
   {       
  print ("Cannot find the PUT UNDER HERE string." );
   }
}
close(ADFILE);

print qq {
<br>
<table>
<tr><td>Information Three</td></tr>
</table>

<br>
<table>
<tr><td>Information Two</td></tr>
</table>

<br>
<table>
<tr><td>Information One</td></tr>
</table>
</body>
</html>
} ;

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Code:
{
   local($^I, @ARGV) = ('.bak',$filename);
   while (<>) {
      if (/^<!-- PUT UNDER HERE -->/) {
         print "<!-- PUT UNDER HERE -->\n";
         print "<br><table border=0>\n";
         print "<TR><td>Information $in(number)</td>\n";
         print "</td></tr></table>\n";
      }
      else {
         print;
      }
   }
}
 
Why do you need to edit an HTML file anyway? If your server already supports CGI (what are you "posting" with?), just have CGI generate the HTML code to begin with, loading the different tables from files to print out as its writing the page.

Code:
#!/usr/bin/perl -w

print "Content-Type: text/html\n\n";
print qq~<html>
<head><title>Post</title></head>
   :
   :
<body>~;

# open the different files with the
# bits of information in them, print
# out new <table>'s for each one here

print qq~</body>
</html>~;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top