Solved

quick help to build HTL page from various files

Posted on 2003-11-10
3
172 Views
Last Modified: 2010-03-04
Here is where I am stuck

if ($dn gt '') &show;

sub show
{
  here is the code I need.  It should:
  1. print "page.htm" with $dn being displayed in it at proper place
  2. while reading "page.htm" to include "text.htm" (as in <!--#include file="text.htm" -->
}

thank you
0
Comment
Question by:versailles
3 Comments
 
LVL 20

Expert Comment

by:jmcg
ID: 9716344
The construct

<!--#include file="text.htm" -->

implies Server Side Includes (SSI). That is another approach to assembing a web page from multiple files, but you don't need anything special in Perl for that — it's something you set up in your web server configuration.

For a one-off situation, you can of course simulate template expansion in a perl CGI script. You'd need to identify where in page.htm the $dn has to be inserted and where to interpolate the contents of text.htm. All of this can simply be printed to the CGI script's STDOUT, preceded by a header identifying it as

Content-Type: text/html

if that's not already supplied.
0
 
LVL 5

Accepted Solution

by:
arjanh earned 250 total points
ID: 9716358
I think this does the trick:

sub show
{
   open( FI, "page.htm" ) or die "Cannot open file page.htm!";
   open( FO, ">newpage.htm" ) or die "Cannot open file newpage.htm for writing!";
   while( <FI> ) {
      if( /\$dn/ ) {
         while( /(.*)\$dn(.*)/ ) {
            $_ = "$1$dn$2";
         }
      }
      if( /#include/ ) {
         while( /(.*)<!--#include +file="(.+)" *-->(.*)/ ) {
            my $res = $1;
            open( FX, $2 ) or die "Cannot open file $2";
            while( <FX> ) {
               $res .= $_;
            }
            close( FX );
            $_ = $res . $3;
         }
      }
      print FO $_;
   }
   close( FI );
   close( FO );
}
0
 

Author Comment

by:versailles
ID: 9717605
arjanh this looks good. I will confirm or ask about if I get a problem. Thx.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl search and replace 6 172
syslog unix file 20 79
Extract data from span tag 1 96
How do I remove several characters from the front of a string in a flat file database. 5 100
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question