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:

use 5.014; # needs (?^mods:pattern) -- also // and s///p from 5.10 use warnings; use strict; my @baza_tek = ( [ '(?^u:ip(\d))' => 'int pro-$1$2' ], [ '(?^u:iipp(\d))' => 'inet proto-$1' ], [ '(?^u:zot(\d))' => 'bang-$2' ], [ '(?^u:zero)' => 'nada-$1' ], [ '(?^u:foo(\d)(\d)?(x))' => 'boo far-$1$2' ], [ '(?^u:udp(\d))' => 'datagram-$1' ], [ '(?^u:NOTHING(\d))' => 'internet protocol-$1' ], # [ '(?^u:BADREGEX+++)' => 'bad regex - match fails' ], ); LINE: while (my $line = <DATA>) { chomp $line; print qq{before substitution(s): '$line' \n}; TUPLE: for my $ar_tuple (@baza_tek) { my ($new_line, $err) = try_substitution($line, @$ar_tuple); if (defined $new_line) { $line = $new_line; # substitution ok if new line defined print qq{ after s/// try: '$line' \n}; } else { # undefined new line: must be an error print qq{$err \n}; } } # end for TUPLE loop print qq{after substitution(s): '$line' \n}; print qq{------------ \n\n}; } # end while LINE loop # subroutines ###################################################### sub try_substitution { my ($string, # string: substitution target $search, # string: search regex $replace, # string: replacement template ) = @_; my (@caps, # all capture groups that might reasonably be used $cap_max, # number of highest capture group actually used $match, # substitution regex match sub-string ); eval { # escalate specific warning to exception-throwing error. use warnings FATAL => 'uninitialized'; $string =~ s{$search}{ # replacement code not entered if search regex throws error. # capture needed dynamic regex variables to external scope. # all capture groups that might possibly appear. @caps = # 0th element is padding (no capture group 0) (undef, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12); # limit capture list to actual capture groups. $#caps = $#-; # max capture group number (0 if none). $cap_max = $#-; $match = ${^MATCH}; qq{qq{$replace}}; }geep; }; # no warnings or any errors in substitution. return $string unless $@; # prepare captured info for 'warning' return. chomp $@; $_ = defined() ? qq{'$_'} : 'undef' for @caps, $match; $cap_max //= 0; # could be undef if search regex threw error # substitution generated warning/exception or an error. return undef, # no successful string substitution join '', qq{ - warning: '$@' \n}, qq{ - for: $search => '$replace' \n}, qq{ - against: $match \n}, ' - ', $cap_max ? qq{$cap_max valid capture(s):} : 'no captures', map sprintf(q{ $%s %s}, $_, $caps[$_]), 1 .. $cap_max ; } # end sub try_substitution() __DATA__ all bad ip6 and zero and zot5 and foo4x thud both ok iipp7 here and iipp8 too and foo42x also bad zot5 thing bad zero here some bad iipp3 and ip4 and foo22x and zot9 and udp2 so-so ok udp7 substitution all ok udp5 and iipp4 and foo98x yea nothing to see here, move along

Output:

c:\@Work\Perl\monks\nikolay>perl templated_substitute_2.pl before substitution(s): 'all bad ip6 and zero and zot5 and foo4x thud' - warning: 'Use of uninitialized value in substitution iterator at t +emplated_substitute_2.pl line 123, <DATA> line 1.' - for: (?^u:ip(\d)) => 'int pro-$1$2' - against: 'ip6' - 1 valid capture(s): $1 '6' after s/// try: 'all bad ip6 and zero and zot5 and foo4x thud' - warning: 'Use of uninitialized value in substitution iterator at t +emplated_substitute_2.pl line 123, <DATA> line 1.' - for: (?^u:zot(\d)) => 'bang-$2' - against: 'zot5' - 1 valid capture(s): $1 '5' - warning: 'Use of uninitialized value in substitution iterator at t +emplated_substitute_2.pl line 123, <DATA> line 1.' - for: (?^u:zero) => 'nada-$1' - against: 'zero' - no captures - warning: 'Use of uninitialized value in substitution iterator at t +emplated_substitute_2.pl line 123, <DATA> line 1.' - for: (?^u:foo(\d)(\d)?(x)) => 'boo far-$1$2' - against: 'foo4x' - 3 valid capture(s): $1 '4' $2 undef $3 'x' after s/// try: 'all bad ip6 and zero and zot5 and foo4x thud' after s/// try: 'all bad ip6 and zero and zot5 and foo4x thud' after substitution(s): 'all bad ip6 and zero and zot5 and foo4x thud' ------------ before substitution(s): 'both ok iipp7 here and iipp8 too and foo42x a +lso' after s/// try: 'both ok iipp7 here and iipp8 too and foo42x also' after s/// try: 'both ok inet proto-7 here and inet proto-8 too and +foo42x also' after s/// try: 'both ok inet proto-7 here and inet proto-8 too and +foo42x also' after s/// try: 'both ok inet proto-7 here and inet proto-8 too and +foo42x also' after s/// try: 'both ok inet proto-7 here and inet proto-8 too and +boo far-42 also' after s/// try: 'both ok inet proto-7 here and inet proto-8 too and +boo far-42 also' after s/// try: 'both ok inet proto-7 here and inet proto-8 too and +boo far-42 also' after substitution(s): 'both ok inet proto-7 here and inet proto-8 too + and boo far-42 also' ------------ before substitution(s): 'bad zot5 thing' after s/// try: 'bad zot5 thing' after s/// try: 'bad zot5 thing' - warning: 'Use of uninitialized value in substitution iterator at t +emplated_substitute_2.pl line 123, <DATA> line 3.' - for: (?^u:zot(\d)) => 'bang-$2' - against: 'zot5' - 1 valid capture(s): $1 '5' after s/// try: 'bad zot5 thing' after s/// try: 'bad zot5 thing' after s/// try: 'bad zot5 thing' after s/// try: 'bad zot5 thing' after substitution(s): 'bad zot5 thing' ------------ before substitution(s): 'bad zero here' after s/// try: 'bad zero here' after s/// try: 'bad zero here' after s/// try: 'bad zero here' - warning: 'Use of uninitialized value in substitution iterator at t +emplated_substitute_2.pl line 123, <DATA> line 4.' - for: (?^u:zero) => 'nada-$1' - against: 'zero' - no captures after s/// try: 'bad zero here' after s/// try: 'bad zero here' after s/// try: 'bad zero here' after substitution(s): 'bad zero here' ------------ before substitution(s): 'some bad iipp3 and ip4 and foo22x and zot9 an +d udp2 so-so' - warning: 'Use of uninitialized value in substitution iterator at t +emplated_substitute_2.pl line 123, <DATA> line 5.' - for: (?^u:ip(\d)) => 'int pro-$1$2' - against: 'ip4' - 1 valid capture(s): $1 '4' after s/// try: 'some bad inet proto-3 and ip4 and foo22x and zot9 a +nd udp2 so-so' - warning: 'Use of uninitialized value in substitution iterator at t +emplated_substitute_2.pl line 123, <DATA> line 5.' - for: (?^u:zot(\d)) => 'bang-$2' - against: 'zot9' - 1 valid capture(s): $1 '9' after s/// try: 'some bad inet proto-3 and ip4 and foo22x and zot9 a +nd udp2 so-so' after s/// try: 'some bad inet proto-3 and ip4 and boo far-22 and zo +t9 and udp2 so-so' after s/// try: 'some bad inet proto-3 and ip4 and boo far-22 and zo +t9 and datagram-2 so-so' after s/// try: 'some bad inet proto-3 and ip4 and boo far-22 and zo +t9 and datagram-2 so-so' after substitution(s): 'some bad inet proto-3 and ip4 and boo far-22 a +nd zot9 and datagram-2 so-so' ------------ before substitution(s): 'ok udp7 substitution' after s/// try: 'ok udp7 substitution' after s/// try: 'ok udp7 substitution' after s/// try: 'ok udp7 substitution' after s/// try: 'ok udp7 substitution' after s/// try: 'ok udp7 substitution' after s/// try: 'ok datagram-7 substitution' after s/// try: 'ok datagram-7 substitution' after substitution(s): 'ok datagram-7 substitution' ------------ before substitution(s): 'all ok udp5 and iipp4 and foo98x yea' after s/// try: 'all ok udp5 and iipp4 and foo98x yea' after s/// try: 'all ok udp5 and inet proto-4 and foo98x yea' after s/// try: 'all ok udp5 and inet proto-4 and foo98x yea' after s/// try: 'all ok udp5 and inet proto-4 and foo98x yea' after s/// try: 'all ok udp5 and inet proto-4 and boo far-98 yea' after s/// try: 'all ok datagram-5 and inet proto-4 and boo far-98 y +ea' after s/// try: 'all ok datagram-5 and inet proto-4 and boo far-98 y +ea' after substitution(s): 'all ok datagram-5 and inet proto-4 and boo far +-98 yea' ------------ before substitution(s): 'nothing to see here, move along' after s/// try: 'nothing to see here, move along' after s/// try: 'nothing to see here, move along' after s/// try: 'nothing to see here, move along' after s/// try: 'nothing to see here, move along' after s/// try: 'nothing to see here, move along' after s/// try: 'nothing to see here, move along' after s/// try: 'nothing to see here, move along' after substitution(s): 'nothing to see here, move along' ------------

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:  <%-{-{-{-<


In reply to Re^4: On error, how to show the regexp values? (tracing warnings) by AnomalousMonk
in thread Tracing warnings: how to show the regexp values? by nikolay

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.