problem writing file

D

David McDivitt

I need help writing a file if someone would oblige. An image is retrieved
from a database, a file opened, and one of the fields written to the file.
When writing normally, extra bytes are added to the data and the image is
not interpretable. Probably Perl is converting control characters. I tried
using sysopen and syswrite so the data would be written as is, but cannot
get the syntax right. The code is pasted here. Thanks

use Fcntl qw( O_WRONLY O_CREAT ); #placed at top of program

sysopen JPGFILE, '>'.$$cfg{'ServerSaveImagePath'}.$jpg, (O_CREAT | O_WRONLY)
or problem('Cannot create image file');

syswrite JPGFILE, $field[0];

#open JPGFILE, '>'.$$cfg{'ServerSaveImagePath'}.$jpg or problem('Cannot
create image file');

#print JPGFILE $field[0] or problem('Cannot write image file');
close JPGFILE;
 
D

David McDivitt

Subject: Re: problem writing file
Date: Fri, 3 Oct 2003 14:09:50 -0500

Would binmode(JPGFILE) work in this case?
My newbie 2 cents.

David McDivitt said:
I need help writing a file if someone would oblige. An image is retrieved
from a database, a file opened, and one of the fields written to the file.
When writing normally, extra bytes are added to the data and the image is
not interpretable. Probably Perl is converting control characters. I tried
using sysopen and syswrite so the data would be written as is, but cannot
get the syntax right. The code is pasted here. Thanks

use Fcntl qw( O_WRONLY O_CREAT ); #placed at top of program

sysopen JPGFILE, '>'.$$cfg{'ServerSaveImagePath'}.$jpg, (O_CREAT | O_WRONLY)
or problem('Cannot create image file');

syswrite JPGFILE, $field[0];

#open JPGFILE, '>'.$$cfg{'ServerSaveImagePath'}.$jpg or problem('Cannot
create image file');

#print JPGFILE $field[0] or problem('Cannot write image file');
close JPGFILE;

Yes, binmode did it. Thanks
 
W

Walt Mankowski

I need help writing a file if someone would oblige. An image is retrieved
from a database, a file opened, and one of the fields written to the file.
When writing normally, extra bytes are added to the data and the image is
not interpretable. Probably Perl is converting control characters. I tried
using sysopen and syswrite so the data would be written as is, but cannot
get the syntax right. The code is pasted here. Thanks

use Fcntl qw( O_WRONLY O_CREAT ); #placed at top of program

sysopen JPGFILE, '>'.$$cfg{'ServerSaveImagePath'}.$jpg, (O_CREAT | O_WRONLY)
or problem('Cannot create image file');

syswrite JPGFILE, $field[0];

#open JPGFILE, '>'.$$cfg{'ServerSaveImagePath'}.$jpg or problem('Cannot
create image file');

#print JPGFILE $field[0] or problem('Cannot write image file');
close JPGFILE;

Are you on a win32 box? If so, try calling binmode on the file handle
before writing to it.

Walt
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top