Solved

Should be easy: Including text

Posted on 1998-07-23
3
150 Views
Last Modified: 2013-11-18
I'm using a perl CGI script to create an HTML page based on certain conditions.

I would like to include text from other files (sort of like a server side include), but I can't seem to do this within the cgi script.

What I'd like to do is almost like a "Location:" redirection, but instead it would just include the text in the specified file rather than redirect the browser to the new url. Then I could also include text from one or two other files, depending on the circumstances.
0
Comment
Question by:csi
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
b2pi earned 50 total points
ID: 1208712
print "Content-type: text/html\n\n";

if (Condition 1) {
   &PFile("File to use if condition1 is true") || handle an error message here.
}

if (Condition 2) {
  &PFile("File to use if condition 2 is true") || handle an error here.
}
 ....


sub PFile ($) {
   my($file) = shift;
   open(F, "<$file") || return 0;
   while (<F>) {
     print;
  }
  close(F);
}
0
 

Author Comment

by:csi
ID: 1208713
Jeez! I thought this was going to be easy. I'll have to try this out.
0
 

Author Comment

by:csi
ID: 1208714
Perfect! Thanks.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
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…
The viewer will learn how to count occurrences of each item in an array.

762 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

18 Experts available now in Live!

Get 1:1 Help Now