in reply to writing a file

What error did you encounter with the die? I don't have a detailed diagnosis -- the list of symptoms you describe is very odd (it doesn't seem to be a permissions problem, unless that's what your die is telling you).

What is the use FileHandle doing here? You don't need it to write to a filehandle, the module is just there to let you treat a filehandle like a scalar. As far as this bit of code is concerned, you never use it. Consider eliminating it (although I don't know that that's the problem). Other questions:

You don't mention specifically whether the print statement *outside* the loop writes to the file, or whether the line of data you've fetched from the DB prints *if* you put it outside the loop.

If the header line prints but not the line within the loop, that would suggest to me that your DB call is failing (why wouldn't it fail when you're printing to the screen? Beats me.)

It's odd that it would write to STDOUT and not to the file if there isn't some problem opening the file.

Update: try adding an "or die" to the $dbh->execute call; that might help here.

Try replacing everything from open on down with something like this:

my $file = "path/to/client.csv"; # make sure this location is writable +! open F, ">$file" or die "Couldn't create $file: $!\n"; print F "CLIENT NAME,DC,FF,OTHERS\n"; while(@row = $dbh->dbnextrow()) { print F join(/,/, @row), "\n"; } close F;

Philosophy can be made out of anything -- or less