Solved

quick help to build HTL page from various files

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

12 Experts available now in Live!

Get 1:1 Help Now