leriksen has asked for the wisdom of the Perl Monks concerning the following question:
My idea was to use (?{...code}) constructs in the regex to count each occurence of 'ab' in the string, and when the end of the string was encountered, do 'something' that made the regex match if the count was odd, and fail if the count was even. I haven' quite divined what that 'something' is yet, as my perl 5.8.2 on RH Linux 7.2 is doing a
when I try using the example from perlrepanic: top_env
#!/usr/bin/perl -w use strict; my $cnt; my $res; my $regex = qr/ (?{ $cnt = 0 }) # Initialize $cnt. (?: # group only a (?{ local $cnt = $cnt + 1; # Update $cnt, backtracking-safe. }) )* aaaa (?{ $res = $cnt }) # success-copy to non-local var /x; foreach my $line (<DATA>) { chomp $line; print STDERR "huzzah |$`| |$&| |$'| $res $line\n" if $line =~ $re +gex; } __DATA__ aaaaaaaa aaaa
I've tracked it down to the (?{local $cnt = $cnt + 1;}) part of the regex - remove that and the panic goes away.
I know the perlre says that (?{...code..}) is
WARNING: This extended regular expression feature is considered highly experimental, and may be changed or deleted without notice.
but I take that to mean experimental from a syntactic and semantic aspect, not nonoperational.
How does one begin to debug such an error ??
+++++++++++++++++
#!/usr/bin/perl
use warnings;use strict;use brain;
|
|---|