For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > November 2005 > Wierd behavior with files. Can anyone explain what is happening?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Wierd behavior with files. Can anyone explain what is happening?
rss@ddsc.com

2005-11-27, 6:59 pm

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. Sinan Unur

2005-11-27, 6:59 pm

rss@ddsc.com wrote in
news:1133127945.552547.62230@g43g2000cwa.googlegroups.com:

> 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:


<URL:http://perl.plover.com/Questions4.html>

> 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

--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/c...guidelines.html
usenet@DavidFilmer.com

2005-11-28, 3:56 am

rss@ddsc.com wrote:
<snip, snip, snip>
> 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/c...guidelines.html

rss@ddsc.com

2005-11-28, 6:59 pm

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.

Tad McClellan

2005-11-28, 6:59 pm

rss@ddsc.com <rss@ddsc.com> wrote:

> 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;


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com