What is the correct way to fix this warning?

I am trying to use this tool. (Perl version) However, when I try to run it using the recommended command perl bin/SWOG.pl --input=examples/simple.swog --toPng=simple, it displays the following warning (added use diagnostics, hoping that it would shed some light on how to fix it)

Variable "$np" will not stay shared at (re_eval 8) line 2 (#1)

(closure W) An internal (nested) named routine refers to a lexical variable defined in an external named routine.

When the internal subroutine is called, it will see the value of the variable of the external subroutine, as it was before and during the first call of the external subroutine; in this case, after the first call, the external subroutine is completed, the internal and external subroutines will not be a longer fraction of the total value for the variable. In other words, the variable will no longer be used.

This problem can usually be solved by creating an internal routine anonymously using the syntax sub {}. When internal anonymous control variables are in external routines, they are automatically restored to the current values ​​of such variables.

I have paid due attention to Google: the link , but still do not understand how to apply this in my case.

, . :

    # parentheses balance pattern
    # @ http://www.unix.org.ua/orelly/perl/prog3/ch05_10.htm
    $np= qr{
       \(
       (
       (?:
          (?> [^()]+ )    # Non-parens without backtracking
        |
          (??{ $np })     # Group with matching parens
       )*
       )                    
       \)
    }x;

, $np $np .

, . !

+4
1

-

sub f {
   my $np;
   $np = qr/...(??{ $np }).../;
}

(??{...}) , .

, , regex qr// , qr// . , , , $np.

, .

sub f {
   local our $np;
   $np = qr/...(??{ $np }).../;
   ... /$np/ ...
}

, regex , qr//, .

sub f {
   my $var = '';
   my $np;
   $np = qr/...(??{ $np })...$var/;
   ... /$np/ ...
}

qr// ? .

my $np;
$np = qr/...(??{ $np }).../;

sub f {
   ... /$np/ ...
}
+5

All Articles