Solved

quick help to build HTL page from various files

Posted on 2003-11-10
3
173 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…

734 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