perl + Win32::OLE + regex = bug

Discussion in 'Perl Misc' started by glob, Jan 18, 2007.

  1. glob

    glob Guest

    #!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
    glob, Jan 18, 2007
    #1
    1. Advertising

  2. glob wrote:
    > #!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
    Mark Clements, Jan 18, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vinay Gupta
    Replies:
    2
    Views:
    1,104
    Michael Schlenker
    Jul 27, 2004
  2. Patrick.O.Ige

    Ole ole

    Patrick.O.Ige, Jul 16, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    488
    Patrick.O.Ige
    Jul 16, 2006
  3. Drew Pihera
    Replies:
    0
    Views:
    637
    Drew Pihera
    Feb 4, 2004
  4. Lance Hoffmeyer
    Replies:
    0
    Views:
    238
    Lance Hoffmeyer
    Nov 17, 2003
  5. Lance Hoffmeyer

    Win32::OLE MS Word line breaks regex

    Lance Hoffmeyer, Feb 3, 2007, in forum: Perl Misc
    Replies:
    1
    Views:
    177
    Mumia W. (NOSPAM)
    Feb 4, 2007
Loading...

Share This Page