LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-02-2009, 11:28 PM   #1
JoeBleaux
LQ Newbie
 
Registered: Mar 2009
Distribution: Slamd64
Posts: 26

Rep: Reputation: 15
Perl: Read a html file and output it...


I'm trying to write a perl script that (at the heart of it) will read an html file one character at a time and send it out via apache.

Meaning a url of:

Code:
http://www.mydomain.com/cgi-bin/read.pl?page=test.html
would read test.html (one character at a time) and send it to Apache to be displayed as a normal web page...

So far I have:

Code:
#!/usr/bin/perl

use CGI qw(:param);

my $page = param('page');

print "Content-type: text/plain; charset=iso-8859-1\n\n";
open FILE, "$page" or die $!;

while($ch = getc(FILE)) {
        print $ch;
        }
 close (FILE);

The page is spit out the web server but, it is displayed EXACTLY (as text) and not as html (meaning the HTML code is visible).

It's late, I'm tired, any ideas?

Last edited by JoeBleaux; 04-02-2009 at 11:46 PM. Reason: Fixed the Param problem
 
Old 04-03-2009, 01:00 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Shouldn't the content-type header refer to 'text/html'?
--- rod.
 
Old 04-03-2009, 04:54 AM   #3
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
...corected... got you wrong. It's the content-type as theNomr said already

Last edited by j-ray; 04-03-2009 at 04:55 AM.
 
Old 04-03-2009, 07:54 AM   #4
JoeBleaux
LQ Newbie
 
Registered: Mar 2009
Distribution: Slamd64
Posts: 26

Original Poster
Rep: Reputation: 15
DOH!!!! Like I said, it was late and I was tired.

I don't care what those BSD guys say about you Linux guys, you're okay by me!
 
  


Reply

Tags
cgi, html, perl



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read HTML or TXT file and output the data? koolkicks311 Programming 1 04-20-2007 11:13 PM
[Perl] cgi.pm - save input in .html file noir911 Programming 2 01-07-2007 02:36 PM
PERL: Can you open an HTML file from a web address? SparceMatrix Programming 3 02-07-2006 11:06 AM
How can i read an write to a HTML or xml file using C alix123 Programming 1 11-24-2004 05:07 AM
cgi perl : I cant get perl to append my html file... the_y_man Programming 3 03-22-2004 05:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration