problem writing file

Discussion in 'Perl Misc' started by David McDivitt, Oct 3, 2003.

  1. 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;
    David McDivitt, Oct 3, 2003
    #1
    1. Advertising

  2. >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" <> wrote in message
    >news:...
    >> 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
    David McDivitt, Oct 3, 2003
    #2
    1. Advertising

  3. In article <>, David McDivitt wrote:
    > 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
    Walt Mankowski, Oct 3, 2003
    #3
    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. Mark Kamoski
    Replies:
    1
    Views:
    2,450
  2. BLF
    Replies:
    4
    Views:
    1,276
    Mike Treseler
    Aug 7, 2004
  3. John Carnahan

    File Access error - writing to .txt file

    John Carnahan, Jul 18, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    801
    John Carnahan
    Jul 18, 2003
  4. HNguyen
    Replies:
    4
    Views:
    2,400
    HNguyen
    Dec 21, 2004
  5. Greg
    Replies:
    9
    Views:
    815
    Nobody
    Oct 8, 2011
Loading...

Share This Page