perl + Win32::OLE + regex = bug

G

glob

#!perl
# highly butchered version of real-world code
# just to demonstrate the issue.
use strict;
use Win32::OLE;
my $field = 'bad@id';
if ($field =~ /^([^\@]+)\@(.*)/) {
my $dom = Win32::OLE->new('Msxml.DOMDocument');
$dom->loadXml('<moo><bad id="1" /></moo>');
$dom->documentElement->SelectSingleNode($1)->getAttribute($2);
}
my $desc = 'i am:testing';
$desc =~ s/^([^:]+)/$1/;
print "$desc\n";
__END__

this prints out "bad:testing", not "i am:testing".

changing the SelectSingleNode calls to create a new string fixes the
problem:
$dom->documentElement->SelectSingleNode("$1")->getAttribute("$2");

i found it interesting that the issue continues even thou $dom is out
of scope.

that is all, just had to share / vent. took me a while to track down.

-byron
 
M

Mark Clements

glob said:
#!perl
# highly butchered version of real-world code
# just to demonstrate the issue.
use strict;
use Win32::OLE;
my $field = 'bad@id';
if ($field =~ /^([^\@]+)\@(.*)/) {
my $dom = Win32::OLE->new('Msxml.DOMDocument');
$dom->loadXml('<moo><bad id="1" /></moo>');
$dom->documentElement->SelectSingleNode($1)->getAttribute($2);
}
my $desc = 'i am:testing';
$desc =~ s/^([^:]+)/$1/;
print "$desc\n";
__END__

this prints out "bad:testing", not "i am:testing".

changing the SelectSingleNode calls to create a new string fixes the
problem:
$dom->documentElement->SelectSingleNode("$1")->getAttribute("$2");

i found it interesting that the issue continues even thou $dom is out
of scope.

that is all, just had to share / vent. took me a while to track down.

For what it's worth, I've raised a bug.

http://rt.cpan.org/Ticket/Display.html?id=24442

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top