Solved

quick help to build HTL page from various files

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

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

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…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
Six Sigma Control Plans

622 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