Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Upgrade to 5.18 causes uninitialized ${^MATCH}

by nbtrap (Sexton)
on May 28, 2013 at 02:02 UTC ( #1035503=perlquestion: print w/ replies, xml ) Need Help??
nbtrap has asked for the wisdom of the Perl Monks concerning the following question:

Upgrading to 5.18 has caused "Use of uninitialized value in subtraction (-)..." to be printed when executing the following code:

while ($buf =~ /$pat/gp) { push @{ $self->{seen} }, [(pos $buf) - length ${^MATCH}, pos $buf] if not $sub or $sub->(substr ${^PREMATCH}, -200); }

I'm certain that the uninitialized value it refers to is that of ${^MATCH}, but I can't for the life of me figure out why it thinks it's undefined.

The chunk of code falls within the context of a larger subroutine, and I've been unable to recreate the error message except during regular execution of the program of which it is a part.

The only sort of "use VERSION" declaration in the entire program is "require 5.010" in a base package. And the code worked fine before upgrading to 5.18. Any ideas?

Comment on Upgrade to 5.18 causes uninitialized ${^MATCH}
Download Code
Re: Upgrade to 5.18 causes uninitialized ${^MATCH}
by AnomalousMonk (Abbot) on May 28, 2013 at 02:24 UTC

    It's possible for either or both of pos or  ${^MATCH} to be undefined after a match, which is easily demonstrated (Perl version 5.14):

    >perl -wMstrict -le "my @strs = (qw(123x foo ***), ''); ;; for my $s (@strs) { $s =~ m{ \d+ }xmsgp; printf qq{for '%s': pos == %s, \${^MATCH} eq '%s' \n}, $s, pos($s) // 'undefined', ${^MATCH} // 'undefined', ; } " for '123x': pos == 3, ${^MATCH} eq '123' for 'foo': pos == undefined, ${^MATCH} eq 'undefined' for '***': pos == undefined, ${^MATCH} eq 'undefined' for '': pos == undefined, ${^MATCH} eq 'undefined'

    Rather than Perl, I think the most likely explanation is that the data you are processing has changed.

    Update: ... and the length of an undef is undefined.

Reaped: [dup: please reap] Re: Upgrade to 5.18 causes uninitialized ${^MATCH}
by NodeReaper (Curate) on May 28, 2013 at 02:37 UTC
Re: Upgrade to 5.18 causes uninitialized ${^MATCH}
by kcott (Abbot) on May 28, 2013 at 03:00 UTC

    G'day nbtrap,

    Welcome to the monastery.

    I'm using 5.18.0. Without any context or knowledge of the values of $buf, $pat, $self or $sub, I am unable to reproduce your problem.

    pos() and ${^MATCH} are returning the values I would expect:

    $ perl -Mstrict -Mwarnings -E ' my $buf = q{aXa}; while ($buf =~ /a/gp) { say q{pos($buf):}; say pos($buf); say q{${^MATCH}:}; say ${^MATCH}; } ' pos($buf): 1 ${^MATCH}: a pos($buf): 3 ${^MATCH}: a

    perldelta (for 5.18.0) mentions a change to ${^MATCH} under Internal Changes which may be relevant.

    perldoc.perl.org hasn't updated to 5.18.0 yet. If you're using online documentation, I suggest using the CPAN perl 5.18.0 doco. (The commandline perldoc utility is up-to-date.)

    You may get some hints for creating a short, self-contained script that reproduces your problem from "How do I post a question effectively?".

    -- Ken

      Thank you. I'm aware of the changes documented in the 5.18 manual pages, but none of them seemed to address this problem. And I know a working script would have been very helpful, but I couldn't get this to work outside the context of my rather large program, so I decided to cross my fingers and hope someone else might be experiencing the same thing.

Re: Upgrade to 5.18 causes uninitialized ${^MATCH}
by dave_the_m (Parson) on May 28, 2013 at 08:50 UTC
    I can reproduce it with the following code, which works in 5.16.x and broke in 5.18.0:
    my $pat = qr/a/; 'aaaa' =~ /$pat/gp or die; print "MATCH=[${^MATCH}]\n";
    Given that it was probably me who broke it, looks like I'll have to get it fixed for 5.18.1.

    Dave.

      Now given ticket RT #118213

      Dave.

      It appears to depend on qr.
      my $pat = qr/a/p; 'aaaa' =~ /$pat/g or die; print "MATCH=[${^MATCH}]\n";
      Appears to work OK on 5.18.0.

      Yes, I overlooked the fact that $pat in my original example was pre-compiled with qr//.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1035503]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (14)
As of 2015-07-02 09:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (33 votes), past polls