in reply to Re: writing a file
in thread writing a file

oops. sorry, didn't align my preformatted text. anyways, here's an easier-to-read reply Ü

basically, the system retrieves data from the database
depending on the value of the fields (analyst, account
type, region, etc...). after generating a report (which is
displayed on the webpage), the fields are stored in the csv
file (client.csv and analyst.csv) in order to generate
their equivalent graph values (Excel graph).

here's the code for generating client.csv....

open F, ">client.csv" or die "couldnt create file $!"; print F "CLIENT NAME,DC,FF,OTHERS\n"; while ((@xgdat) = $dbh->dbnextrow(1)) { $xgdat[0] =~ s/\,/ /g; print F "$xgdat[0],$xgdat[1],$xgdat[2],$xgdat[3]\n"; } close F, "client.csv";
apparently, the data IS written to the file provided the command (i.e. print F "$xgdat0,$xgdat1,$xgdat2,$xgdat3\n";) is NOT in a loop. we tried writing it to the console (w/ the command still in the loop) and there were no problems encountered. we still don't know why this happens. btw, we also encountered an error with the die statement after opening the file. thanks again!

Replies are listed 'Best First'.
RE: RE: Re: writing a file
by Fastolfe (Vicar) on Oct 03, 2000 at 18:24 UTC
    So let me get this straight:
    1. You got an error message while attempting to open your file (via die)
    2. If you print to the console instead of to your file, everything succeeds
    3. If you try to print to your file (which failed to open per #1), it fails
    Hmm...

    Did you try looking at the error message? What did the error message say? If you got an error message while attempting to open your file, I would probably have to say that the file was not opened, which explains why your print statement to the file failed to work.

    Note that "die" isn't giving you an error message. It simply relays the error message to you and stops execution of your script. If the open call failed, you would not know about it unless you checked the return value of open, and did something with it (in this case, we use 'or die ...' to print out an error message if something went wrong and exit the script).

    Clearly, your open is failing, for the reasons explained by the error message you received.