Dear Mark,

> Long time lurker, first time poster...please be gentle.

Shame you missed the many comments on strict and
warnings.  Consider these mandatory whilst learning: 

use strict;
use warnings;

I am not familar with Win32::OLE, but there is certainly
some errors in your code I can show you.  And some
suggestions to help.

> $articleDirName = "c:\\work\\test\\psq\\test\\";

Avoid the backslashes, try using single quotes instead.

> unless (opendir(DIR, $articleDirName)) {
>         warn "Can't open $articleDirName\n";
>         closedir(DIR);
>         exit(1);
> }

I like the fact you are checking the result of opendir, but
the action to take is flawed.  If the directory open failed,
what are you closing?

Remember that die() is available, if you want to warn and
exit.  Makes for shorter code, but you don't get to choose
the error number (see "perldoc -f die" for what you do get).

> foreach (readdir(DIR))
> {
>     next if $_ eq '.' || $_ eq '..';
>     $path = "$articleDirName$_";
>     if (-f $path){
>         if ($path =~ /\.fin/i){
>             $doc = Win32::OLE->GetObject($path);
>             $fileName = $path . ".rtf";

Consider using "$path.rtf" or "${path}.rtf", although that is just my
perference.

>             print "$fileName\n";
>             $doc->ActiveDocument->SaveAs({FileName => $fileName,
> FileFormat => wdFormatRTF})

'Can't call method "SaveAs" on an undefined value'.

That clearly means that "$doc->ActiveDocument" evaluates to be
undefined.  I think you need: "$doc->ActiveDocument()->SaveAs",
those brackets telling perl it should be calling SaveAs on the value
returned by the ActiveDocument() method.

This might have been caught better using strict.  Try.

>         }
>         undef $doc;
>         undef $path;
>         undef $fileName;

If you had declared your variables as lexically scoped, using my,
then you wouldn't have to undef them.  With strict you will HAVE
to learn to use "my" and "our".

>     }
> }
> 

So, the main lesson of the day is USE STRICT.  You will save
days of debugging, which must qualify as being kind (if not gentle ;-)

Jonathan Paton

-- 
#!perl
$J=' 'x25 ;for (qq< 1+10 9+14 5-10 50-9 7+13 2-18 6+13
17+6 02+1 2-10 00+4 00+8 3-13 3+12 01-5 2-10 01+1 03+4
00+4 00+8 1-21 01+1 00+5 01-7 >=~/ \S\S \S\S /gx) {m/(
\d+) (.+) /x,, vec$ J,$p +=$2 ,8,= $c+= +$1} warn $J,,

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to