Solved

quick help to build HTL page from various files

Posted on 2003-11-10
3
170 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hard perl script 16 156
ppm conversion to curl on a module install 8 82
Perl script to find new files and compress those new files 5 94
Call Shell Script from Perl Script 6 97
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…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now