in reply to Win32::OLE word questions

I don't know if it's a typo, or a cut and past error, but your use strict statement is missing the semicolon at the end ;

Since you are using strict, you will need to declare your variable, $rate with "my" as in:
my $rate;
You say it all fails. Do you get any error messages to help indicate where it is failing? One error that I get is "Does not support a collection" in METHOD/PROPERTYGET", referring to the line:
foreach $rate($Word->ActiveDocument->Selection->{Text}
And also "Can't use an undefined value as a HASH reference". You might start by looking at your syntax in that bit of code.
What is your end-goal for this script?

Have you read the Win32::OLE documentation at ASPN?

Replies are listed 'Best First'.
Re: Re: Win32::OLE word questions
by rootstock (Novice) on May 13, 2003 at 01:09 UTC
    sorry, the first line should be #use strict and the semicolon was exist.
    since the program doesnot work that i am still revise it very often,
    my end-goal is that
    foreach $rate($Word->ActiveDocument->Selection->{Text}){ #get all content of the activedocument
    if ($rate =~ /2M/){ #if $rate could match the keyword
    print $rate; }} #print it out

    $Word->ActiveDocument->Selection->{Text};
    $line1 = $Word->Selection->wdline(2)->{Text}; #get or extract all the words of the second line of the active document
    pirnt $line1;

    i have read win32::ole documentation, but this is the first time i have written the ole word script, i am fairly strange at the ole processing. i know my problem is the method invoking, i have revised more then ten times, i have no idea where the error is.