in reply to Tracing warnings: how to show the regexp values?

I order to capture a warning for debugging, you could (locally with local ) change sigwarn

DB<120> $SIG{__WARN__} = sub { print "<<<$_[0]>>>" } DB<121> warn "xxx" <<<xxx at (eval 58)[multi_perl5db.pl:644] line 2. >>>

you can also run perlcode in a regex which checks $2 explicitly

edit

like in

DB<133> $x =~ s/ (?{ print "\$2 undefined" unless $2 })/ /g $2 undefined

And finally: please note that you are already using two eval levels with /ee (why?) so how to run check code should be obvious.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^2: On error, how to show the regexp values? (tracing warnings)
by Anonymous Monk on Jan 07, 2017 at 15:35 UTC

    Even outside the debugger, you can establish a warnings handler:

    #!/usr/bin/perl use warnings; use strict; my $sod='ip6 is used for...'; my $i=0; my @baza_tek=qw( (?^u:ip(\d)) "internet_protocol-$1$2" ); { local $SIG{__WARN__} = sub { warn @_; warn "\$baza_tek[$i] is '$baza_tek[$i]"; my $j = $i + 1; warn "\$baza_tek[$j] is '$baza_tek[$j]"; }; $sod=~s#$baza_tek[$i]#$baza_tek[$i+1]#gee; }

    And the reason $2 is undefined is that your regular expression has only one capture group, (\d).

        >> has only one capture group, (\d).

        > capture groups are unrelated to \d

        Capture groups in general are unrelated to \d, but nonetheless the lone capture group in the regexp is (\d).

        > The outer parens would capture without the colon :

        Also correct. But in fact the outer parens do have the colon, so they do not capture.

      Awesome! Thank you very much!

      But farther testing, on real data (that is much and is taken from different sources) did show, that the kind of exception, shows not the culprit at the time the error occurs. -- Like, if we have 1 000 patterns, and pattern #345 contains the error in focus, then the exception will show, say, pattern #378 -- back or forth in the row of patterns from the problem pattern, i do not know, having brought that exapmple just for better illustration of what i mean.

      Personally, i think that the PERL mechanism for error handling, simply is late, and except it can be fixed, i think additional peace of code needs to be written like above have said -- that checks every pattern regexp, but, again, then we will get a lot matches, among whom will be the culprit.

      So, before getting that mess of results, in order to make things done, i ask here for "wisdom" -- as it is kept saying here. ;-)

        Of course, you don't give a code example showing the problem(s) you are encountering. Even so, here's some code that might be food for thought, incorporating a number of guesses on my part.

        File templated_substitute_2.pl:

        Output:

        Note that the faulty regex example
            # [ '(?^u:BADREGEX+++)'     => 'bad regex - match fails' ],
        will appear for every line processed if you enable it; it's just there to show the effect.


        Give a man a fish:  <%-{-{-{-<