Google Answers Logo
View Question
Q: PERL command to print HTML file ( Answered 5 out of 5 stars,   1 Comment )
Subject: PERL command to print HTML file
Category: Computers > Algorithms
Asked by: cluelessone-ga
List Price: $5.00
Posted: 17 May 2006 06:56 PDT
Expires: 16 Jun 2006 06:56 PDT
Question ID: 729718
I need a PERL command that will "print" the contents of an HTML file.
I want to create some complicated HTML, save it in a file, and then
have my PERL script show that to the user. Including the HTML in the
PERL script makes it difficult to update, easier to do it in an
external file.
Subject: Re: PERL command to print HTML file
Answered By: palitoy-ga on 17 May 2006 07:12 PDT
Rated:5 out of 5 stars
Hello cluelessone-ga,

Thank-you for your question.

The easiest way to do this is to collect all the information you have
output into the HTML file and print it on the screen.

This can be done using this small snippet.

If you have any questions or require any further assistance please do
not hesitate to ask for clarification.

# read the html file into an array
open (TXTFILE, "/path/to/file.html");
@lines = <TXTFILE>;

# place the contents of the @lines array into a variable
$all_lines = join("",@lines);
# replace the < character with its HTML equivalent &lt;
# this enables the code to be viewable
$all_lines =~ s/</\&lt;/g;

print $all_lines;
cluelessone-ga rated this answer:5 out of 5 stars

Subject: Re: PERL command to print HTML file
From: frankcorrao-ga on 17 May 2006 09:13 PDT
it sounds to me like what you really need here is a templating system.
 The standard way to do this is with the HTML::Template package:

If you are unfamilair with what i mean by "html templating", basically
you save an html file that has special tags which let you inline
variables and loops etc from perl.  Then in your perl script, you set
the variables etc.  Like magic, everything is replaced in the html
file with the values of the variables from your perl script.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

Google Home - Answers FAQ - Terms of Service - Privacy Policy