Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File read into program isn't all there

Status
Not open for further replies.

Kathy1

Programmer
Dec 21, 2000
39
0
0
US
Hi.

I have a problem with a subroutine I wrote. It opens and HTML page, reads it into an array, and then writes the HTML page to SYSOUT (the users PC screen). It also inserts variables and stuff that the Javascript in the system needs, but that isn't where the problem is. Anyway, it works most of the time just fine.

Problem is, sometimes when it reads the HTML file in, it isn't getting the whole file. So when it tries to send it to SYSOUT (the screen), most of the file gets written out, and then the whole process stops. So I end up with a blank screen. When I do a 'view source' on the HTML, part of it is there, and the browser just keeps 'spinning', waiting for the rest which never comes.

Here is the code I'm using for this:

#open the HTML file - this file should already exist.
open (HTMLFILE, &quot;<$HTMLPageName&quot;) || die &quot;Cannot find HTML file.
Please note this message and contact the ZZZ help
desk at (999)999-999 or 1-800-999-999 ext \#655.
Program readSendHTML in HTMLIO.PM&quot;;

#store HTML file in array
@indata = <HTMLFILE>;
close (HTMLFILE);

foreach $i (@indata)
{
#remove end of line character from record incoming
chomp($i);

#print the regular HTML line of code and end of line aracter
print &quot;$i \n&quot;;

}

This is a nutshell version of the code just showing the I/O parts of the HTML file being read.

Anyway, I'm wondering what might be causing the whole file to not be read into the array. I've read some information regarding buffers and such, but haven't used them, flushed them, or anything else. Any ideas and thoughts on this would be much appreciated.

Thank you!

Kathy





 
try inserting this line near the top of your program (before any print statements):
Code:
$|=1;
[\code]
Your problem may be not that your input isn't being read, but that your output isn't being completely flushed from the output buffer. That statement will force perl to flush the output buffer every time you &quot;print&quot;. I use it in all my cgi programs to make sure all my output actually gets where it's supposed to go.
 
You should not need to set 'autoflush' to on. Worst case, slowest possibility is that the output buffer holds something until the script exits, providing the code is exiting normally. When the script does 'exit' normally, the output buffer is flushed and you get your output. I don't say this to argue how to use 'autoflush'. Rather, to point out that there must be something else going on. You might use autoflush to treat the symptom, but, you are not curing the desease. With small programs with limited output, setting autoflush to on is not a big deal. With programs that produce a lot of output, it can cause performance problems. Unfortunately, I don't see anything in the code you posted that would cause your problem. It sounds like you are compiling and starting OK, but at some point, the code might be dying abruptly, leaving any buffered output unsent.

Sorry to not be more help.

Good Luck.


keep the rudder amid ship and beware the odd typo
 
thank you goboating and tsdragon.

I do believe there is something other than the buffer flushing going on. This is the same system that I posted another message about the programs themselves getting stuck in very odd places (like on a $var1 = 3; statement, for example). It seems like these are two separate problems, but I believe that somehow they are related.

Anyway, I am trying the autoflush. I put it in the top of the subroutine, rather than in all the programs that call the subroutine. I hope that that is ok. Trying to determine if it is slowing the system down. The pages being loaded out, for the most part, are actually quite small. We send out several lines of HTML, and which then call Javascript subroutines that do the building of the page. So the HTML itself isn't huge. Will this autoflush only affect the HTML, or will it also affect sending the images and Javascript from the server to the client? Also, does it hurt if I put it in the subroutine, instead of the calling program?

Thanks!

Kathy
 
Setting autoflush on, causes the printer buffer size to go to zero. That way nothing is buffered. Everything goes out immediately.

I don't think it will effect your images. Your images are likely going to the browser as a result of a request from the borwser to the web server for the images. You might be using Perl to build the HTML or javascript that runs in the browser, but the browser actually requests the images, just like they are separate documents....... unless you are doing something tricky.

You can manipulate $| anywhere you want. Set it 'on' or 'off' as you like.

HTH


keep the rudder amid ship and beware the odd typo
 
Thanks goboating. I will play with it and see if it at least resolves the screens not fully loading into the browser problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top