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

Discussion in 'Perl Misc' started by rss@ddsc.com, Nov 27, 2005.

  1. Guest

    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??
     
    , Nov 27, 2005
    #1
    1. Advertising

  2. wrote in
    news::

    > 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 <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Nov 27, 2005
    #2
    1. Advertising

  3. Guest

    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/clpmisc/clpmisc_guidelines.html
     
    , Nov 28, 2005
    #3
  4. Guest

    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.
     
    , Nov 28, 2005
    #4
  5. <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Nov 28, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. renata
    Replies:
    1
    Views:
    812
    Kevin Spencer
    Jun 25, 2003
  2. Michael Tsai
    Replies:
    3
    Views:
    480
    Michael Tsai
    Aug 19, 2005
  3. Wookie
    Replies:
    2
    Views:
    342
    Mr Newbie
    Nov 13, 2005
  4. John Dean
    Replies:
    4
    Views:
    272
    John Dean
    Sep 15, 2003
  5. Sharon
    Replies:
    3
    Views:
    310
    Julian Turner
    Nov 19, 2004
Loading...

Share This Page