in reply to Re^3: Working with word document
in thread Working with word document

Here is the corrected code

#!/usr/bin/perl use 5.010; use strict; use warnings; open my $fh,'<','file1.doc' or die "can't open file:"; open my $fh2,'>>','file2.doc' or die "can't open file:"; while(<$fh>) { print $fh2 "$_"; } close $fh2 or die "can't close file:"; close $fh or die "can't close file:";

but still the .doc is blank. P.S: I can see the .doc file size is expanding each time I run the program. For Example, when I run for the first time the .doc file size is 13KB. For the second time it is 26KB and it keeps increasing as I run the program.

Replies are listed 'Best First'.
Re^5: Working with word document
by 2teez (Vicar) on Aug 27, 2012 at 23:43 UTC
    Hi,

    see this: open my $fh2,'>>','file2.doc' or die "can't open file:";
    With the double arrow ">>" the file file2.doc is created if it doesn't exist, but if it does, it "appends" to the file.
    Thus, the increase in the size of the file. So, to just add to the file you will use do like so:
    open my $fh2,'>','file2.doc' or die "can't open file:";
    Please check open for more detailed information.

      I'm guessing he's trying to modify a MS Word document.