Wierd behavior with files. Can anyone explain what is happening?

R

rss

Hello I have a bit of CGI code which works fine which writes a file and
sends an email fine

I add a simple open file and close file after closing bothe files and
suddenly the HTML part which finished at the top causes an error

The file by the way is created just fine. It only causes the HTML
displayed to the bowser to mess up somehow? How why? WIERD?

Can anyone explain this?? I thought perhaps it had to do with
flushing the fuffer and so I tried the following:

select(STDOUT);
$| = 1;

after the last <./HTML> tag is written out. The whole thing is really
strange. Does anyone have any theories as to what went wrong?

Again the only thing that messes up happens when I add the three
statements is the web page. The rest of the program completes. If that
is not the wierdest behavior!!!


open xfile, "> $xfilename" || die "can not open $xfilen
ame";
print fedxfile sprintf("Mytest\n");
close(fedxfile);

comment the above 3 lines and all works fine
As I said even when the HTML part fails the added statements above work
and the output files shows up as one would expect!


I have a workaround but perl definitely appears to behave extremely
wierd regarding this. Anyone know why??
 
A

A. Sinan Unur

(e-mail address removed) wrote in
Hello I have a bit of CGI code which works fine which writes a file
and sends an email fine

I add a simple open file and close file after closing bothe files and
suddenly the HTML part which finished at the top causes an error

The file by the way is created just fine. It only causes the HTML
displayed to the bowser to mess up somehow? How why? WIERD?

Over the top statements instead of facts is not going to help us help
you at all. Please read the posting guidelines for this group to learn
how you can help yourself, and help others help you.
Can anyone explain this??

You have shown nothing that can be explained. My guess is, you have one
or more bugs in your code.

At the very least, you should post a short, self-contained, strict and
warnings compliant script that still exhibits the behavior that's
puzzling you.
I thought perhaps it had to do with
flushing the fuffer and so I tried the following:

after the last <./HTML> tag

I don't think such a tag exists.
open xfile, "> $xfilename" || die "can not open $xfilename";
print fedxfile sprintf("Mytest\n");
close(fedxfile);

Now, do you realize that xfile and fedxfile are not the same file
handles?
I have a workaround but perl definitely appears to behave extremely
wierd regarding this.

This has nothing to do with Perl behaving weirdly (note the spelling).

There are one or more bugs in the code you have not shown us.

Sinan
 
U

usenet

open xfile, "> $xfilename" || die "can not open $xfilename";
print fedxfile sprintf("Mytest\n");
close(fedxfile);

comment the above 3 lines and all works fine

That's because the three lines above are buggy). Look closely. You
open a handle named "xfile" and then attempt to print/close a handle
named "fedxfile". Perl doesn't understand why you seem to think these
are the same thing.

And why on earth are you using sprintf:
print fedxfile sprintf("Mytest\n");

And you should capture the error in your die statement - ie,

open xfile, "> $xfilename" || die "can not open $xfilename - $!";

And I recomend that you read the posting guidelines for this group,
which will assist you in crafting an effective question (and
accumulating good will among the regular posters):
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
 
R

rss

Boy I do not know how I missed such a simple thing! wow!
I am going to check that again. I thought that code was working I see
what you mean though.
 
T

Tad McClellan

Boy I do not know how I missed such a simple thing! wow!


If you always enable warnings when developing Perl code then...

I am going to check that again.


.... you won't have to check that, as the machine will find such mistakes.


Ask for all the help you can get:

use warnings;
use strict;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top