Subject: | numbered match variables become stuck if used as arguments in call to Win32::OLE object |
With the script below, the value of $1 appears to get "stuck" as what it
was before the method call on $dict. Note that the actual type of COM
object used does not appear to be important, and neither does the method
call (in fact, the method doesn't even have to exist). In this example,
$2, which is quoted for the method call, does not become stuck.
use strict;
use warnings;
use Win32::OLE;
my $field = 'bad news';
my $dict = Win32::OLE->new('Scripting.Dictionary');
if ($field =~ /(.*)\s(.*)/) {
$dict->Add("1",$1);
$dict->Add("2","$2");
}
my $desc = 'I am testing';
if($desc =~ /(I)\s(am)/){
print "captured $1 $2\n";
}else{
print "No match\n";
}
C:\Program Files>perl testregex2.pl
captured bad am
C:\Program Files>perl -v
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
I may just have misunderstood the way Win32::OLE works, but this
behaviour seems counterintuitive nonetheless.
regards,
Mark