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

Dear perl monks, I need to extract a list of c void functions/API documentation from a word document to a text file (.cpp files).
I use activeperl 5.10 in windows xp. Here's the code (Heavily borrowed from here ):
use warnings; use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; my $MYDOC = "C:\\Document and Settings\\mhd\\My Documents"; my $DOCFILE = "$MYDOC\\work\\apifunc.doc"; #open STDERR, ">errlog.txt"; my $document = Win32::OLE->GetObject($DOCFILE) or die("Unable to open +document ", Win32::OLE->LastError()); #close STDERR; open FH,">functionList.cpp"; my $pat='\d{1,2}\.(\s)+(V|v)oid'; my $paragraphs = $document->Paragraphs(); my $par; my $enumerate = new Win32::OLE::Enum($paragraphs); while(defined($par = $enumerate->Next())){ if($par =~ m|$pat| ){ print FH; } } close (FH) or die "can't close :$! \n";
the error:
Unable to open document Win32::OLE(0.1709) error 0x800401ea: "Moniker +cannot open file" after character 0 in "C:\Document and Settings\mhd\My Documents\work\apifunc.doc" at extractfunctionName.pl line 13.
What's wrong? I have no idea how to fix it. Any help is appreciated. Thanks.

Replies are listed 'Best First'.
Re: Error opening ms word document
by grizzley (Chaplain) on Mar 05, 2009 at 12:48 UTC

    You made a typo :)

    Instead of 'C:\\Document and Settings' you should write 'C:\\Documents and Settings' ('s' missing)

    Additionally I got error 'Use of uninitialized value $_ in print at ...', you will have to change print to something like print FH $&

      Thanks for pointing the typo,grizzly. But now the script seems running but the result file is empty O_o
      I tried with print FH $& ; or print FH $_ ; even print FH "\nzzzz"; Still empty file is all I got. What's wrong?
        You have if(...) Maybe this is always false in your case?
Re: Error opening ms word document
by Anonymous Monk on Mar 06, 2009 at 08:29 UTC