in reply to writing a file

Please provide additional information. An error message would be most helpful. I can't see anything immediately obvious with your code (except close does not use a 2nd filename argument like you're providing). You should also be checking the return values from your open statement, and ideally even your close statement:
open F, ">client.csv" or die "Couldn't open client.csv: $!"; ... close F or die "Error writing to client.csv: $!";

Replies are listed 'Best First'.
RE: Re: writing a file
by Anonymous Monk on Oct 03, 2000 at 08:56 UTC
    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!
      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.

RE: Re: writing a file
by Anonymous Monk on Oct 03, 2000 at 08:51 UTC
    ok Ü
    
    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 writing to 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 "$xgdat[0],$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!