rajkrishna89 has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks i have written a script to extract a line after a particular id from a .doc document...The problem is the script works for only .txt files but not for .doc files ..

use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; use strict; use warnings; my $in_file = 'D:\kk check perl\check.doc'; open my $in_fh, '<', $in_file or die "Could not open file $in_file: $! +"; my $out_file = 'output.xls'; open my $out_fh, '>', $out_file or die "Could not open file $out_file: +$!"; my $print_next = 0; while ( my $line = <$in_fh> ) { if ($print_next){ print $out_fh $line; #No need to chomp - we print the "\n" } $print_next = ($line =~ /^Derived\sRequirement : \sYes/); } close $in_fh or die "Could not close file $in_file: $!"; close $out_fh or die "Could not close file $out_file: $!";

How the script should be modified to work for .doc files?

Thank u monks

Replies are listed 'Best First'.
Re: Perl script for .doc files
by Ratazong (Monsignor) on Dec 21, 2011 at 07:13 UTC

    Working with word-documents is more that just adding a use Win32::OLE::Const 'Microsoft Word'; to the beginning of your code.

    You should google on how to use it, and by that you might stumble on the following helpful tutorial/example: Win32::ole and MSWord.

    HTH, Rata

Re: Perl script for .doc files
by Anonymous Monk on Dec 21, 2011 at 07:39 UTC