CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
cannot open and print text file!

 



kade
Deleted

Jun 21, 2000, 3:30 AM

Post #1 of 4 (391 views)
cannot open and print text file! Can't Post

2 questions here!
1.I build a webboard.It works perfectly on a trial in my virtual web server(OMNI httpd 2.03),but when uploaded it has a defect.
data in text file is not displayed on browser.
here is my scripts:
print"content-type:text/html\n\n";
print"<html><body>";
ReadParse(*input);
print"content-type:text/html\n\n";
print"<html><body>";
<html>
<body>
<p><img src="http://www.mombuddy.com/mombuddyban.jpg" width="750" height="26"
alt="mombuddyban.jpg (13918 bytes)"></p>

<p align="center"><img src="http://www.mombuddy.com/webboardbear.gif"
width="200" height="119" alt="webboardbear.gif (9467 bytes)"></p>
<p align="left"><big><strong><a
href="http://www.mombuddy.com/qform.htm">Post new question</a>&#3656;</strong></big></p>
<hr align="left">
<p align="left"><big><strong>topics</strong></big></p>
</body>
</html>
text
----#all of the above works,but below it doesn't work-------
open (TOC,"http://www.mombuddy.com/toc.txt");
@data=<TOC>;
close (TOC);
print "@data";
------------------------------
my text file Frowntoc.txt)
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<title>Favorites</title>
<meta name="Microsoft Theme" content="global 101, default">
<meta name="Microsoft Border" content="tl, default">
</head>

<body>

<p>First question </p>

<hr align="center">

</body>
</html>
--------
help me please!


Cretep
User

Jun 21, 2000, 6:02 AM

Post #2 of 4 (391 views)
Re: cannot open and print text file! [In reply to] Can't Post

Hi
Here is your problem

open (TOC,"http://www.mombuddy.com/toc.txt");

To open file you must use the absolute path, like this

open (TOC,"/home/mombuddy/public_html/toc.txt");

And depending on the server configuration and wether or not the script is in the same directory you could use just the file name like this

open (TOC,"toc.txt");

Regards

Peter Crouch


Kanji
User / Moderator

Jun 21, 2000, 11:35 AM

Post #3 of 4 (391 views)
Re: cannot open and print text file! [In reply to] Can't Post

Always, always, always check the return value from something from open(): it saves your sanity.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

# Kill the script
open FILE, $file
or die "Can't open $file because $!";
#
# Just complain.
if ( open FILE, $file ) {
&do_stuff_with( <FILE> );
close FILE;
} else {
warn "Can't open $file because $!";
}</pre><HR></BLOCKQUOTE>


kade
Deleted

Jun 21, 2000, 3:44 PM

Post #4 of 4 (391 views)
Re: cannot open and print text file! [In reply to] Can't Post

To Peter and Kanji,
Hooray! \(^0^)/it works now!
Thanks a lot Smile
I'm so grateful.
Thanks thanks thanks...
Kade

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives