Show contents of text file...
Ok, I think this is pretty easy. What I need to do is show the contents of a text file (multiple lines) in a CGI generated HTML file. How do I do this?
------------------
The fireburn.com Network:
Justin Stayton - [email] [icq]
Rob Pengelly posted this at 15:33 — 27th February 2000.
They have: 850 posts
Joined: Jul 1999
Try somthing like:
open(IN,"<file.txt");
@data = <IN>;
close(IN);
print "Content-type:text/html\n\n";
print @data;
This would open file.txt, put each line as an element in an @array and than print the @array.
Is that what you needed or no?
------------------
Windmills always turn counter-clockwise. Except for the windmills in Ireland.
http://www.thehungersite.com - http://www.therainforestsite.com
http://www.ratemymullet.com - Beauty is only mullet deep.
Orpheus posted this at 19:01 — 27th February 2000.
They have: 568 posts
Joined: Nov 1999
let me add on to that
if you want to replace every \n (standerd UNIX line break) with a <br> tag use a regular expression
open(file,"file.txt");
local($/);
$file = <file>;
close(file);
$file =~ s/\n/<br>/;
print $file;
hope that helps
Justin S posted this at 23:05 — 27th February 2000.
They have: 2,076 posts
Joined: Jun 1999
Ok, I think that's what I want, but it's giving me a 500 Internal Server Error. Here is the code:
Justin Stayton - [email] [icq]
japhy posted this at 00:26 — 28th February 2000.
They have: 161 posts
Joined: Dec 1999
Heh, I see the problem. From the perldata documentation:
Because variable and array references always start with '$', '@', or '%', the "reserved" words aren't in fact reserved with respect to variable names. (They ARE reserved with respect to labels and filehandles, however, which don't have an initial special character. You can't have a filehandle named "log", for instance. Hint: you could say open(LOG,'logfile') rather than open(log,'logfile'). Using uppercase filehandles also improves readability and protects you from conflict with future reserved words.)
The section in bold is the most relevant. It is considered good Perl style to use words in all capital letters for filehandles. Your problem is the fact that "log" is the name of a function in Perl. Try using "LOG".
------------------
--
MIDN 4/C PINYAN, NROTCURPI, US Naval Reserve
Justin S posted this at 02:48 — 28th February 2000.
They have: 2,076 posts
Joined: Jun 1999
Aha! Thanks a lot! I got it to work now...
------------------
The fireburn.com Network:
Justin Stayton - [email] [icq]
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.