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!

reusing HTML code 1

Status
Not open for further replies.

JimJx

Technical User
Joined
Feb 16, 2001
Messages
202
Location
US
Hi all,

I think I know the answer to this question, but will ask anyway.....

The server I am on does not allow SSI, but I have several pages where there is a lot of static HTML code. I was using print<< statements to work around that when I only had 2 pages to worry abuot. But the project has been expanded to roughly a dozen pages and I don't want to have to use that on every page.

So, my thinking was to place the here statements in seperate files and reference them by something like

Code:
open TOP, 'top.cgi';
while (<TOP>)
print "$_";
}

but that isn't working.

Any suggestions?

Thanks!
Jim
 

Your while loop is not set properly.

Code:
open TOP, "top.cgi" || warn "$!\n"; #you may need to define the absolute path to top.cgi and print out a warning if it cant' find it.
while (<TOP>) {--> is missing
print "$_";
}
close TOP;
 
The actual site I am working on resides on another system, so it was not a copy & paste. I did spot the missing { right after I posted. But I think what killed it was I screwed up and put the close statement before the } ....

I think just getting away from it for a few minutes really helped.

Thank you for the reply, Max, I do appreciate you taking the time to read and respond.

Jim
 
Not a solution, which you already have, but a tidbit to take away with you...

The loop you have written can also be written:

Code:
open FILE,"top.cgi";
print while <FILE>;
close FILE;

or even more concisely:

Code:
open FILE,"top.cgi";
print <FILE>;
close FILE;
 
You could use the HTML::Template module for this. The TMPL_INCLUDE tag will allow you to bring in other files too.
 
Template::Toolkit has some pretty good <include> type processing which also supports nested operation (including another include) loops, conditionals etc.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::PerlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top