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

Hi,

ofcourse, the .doc file will be blank with this:

... while(<fh>) ## note this <fh> Oops { print fh2 "$_\n"; ## note this fh2 Oops } ...
but not with this:
... while(<$fh>) ## this is correct $fh { print $fh2 "$_\n"; ## correct $fh2 } ...
The filehandles are $fh and $fh2 NOT fh and fh2!!!
Moreover, if you use warnings and strict you will pick this easily.
Hope this helps

Replies are listed 'Best First'.
Re^4: Working with word document
by nick321 (Initiate) on Aug 27, 2012 at 23:15 UTC

    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.

      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.