rsFalse has asked for the wisdom of the Perl Monks concerning the following question:
Hello.
Today I found a strange behaviour in my sandbox program after I tried to soft-code a variable. Here is my code:
Today I found a strange behaviour in my sandbox program after I tried to soft-code a variable. Here is my code:
#!/usr/bin/perl use warnings; use strict; $\ = $/; my $A = "1112" # . '' ; @_ = ( 'a' .. 'i' ); $A =~ /1+ (??{ print "[$&]"; $_ .= shift @_; s!\B!shift@_!e; print "\$_:[$_]"; }) $ /x;
OUTPUT:
Perl v5.30.0
I tried to minimize the code. But I can't find to how minimize it further.
I don't know why this strange behaviour occurs. It looks kinda bug? Ofc, I coded with very bad practice = I was changing my regex on the fly.
Problem with... backtracking? lexical $_ binded to $A?
The same code except one line being un-commented:[111] $_:[1b112a] [11] $_:[1db112ac] [1] $_:[1fdb112ace] [11] $_:[1hfdb112aceg] [1] Use of uninitialized value within @_ in substitution iterator at ./str +ange_ARG_inside_regex.pl line 18. $_:[1hfdb112acegi] [1] Use of uninitialized value in concatenation (.) or string at ./strange +_ARG_inside_regex.pl line 17. Use of uninitialized value within @_ in substitution iterator at ./str +ange_ARG_inside_regex.pl line 18. $_:[1hfdb112acegi]
OUTPUT (is variable):#!/usr/bin/perl use warnings; use strict; $\ = $/; my $A = "1112" . '' ; @_ = ( 'a' .. 'i' ); $A =~ /1+ (??{ print "[$&]"; $_ .= shift @_; s!\B!shift@_!e; print "\$_:[$_]"; }) $ /x;
Output varies, but when I run similar code inside a FOR loop with ~1e4 iterations I got a similar small number of hash values.[111] $_:[1b112a] [11] $_:[1db112ac] [�] $_:[1fdb112ace]
Perl v5.30.0
I tried to minimize the code. But I can't find to how minimize it further.
I don't know why this strange behaviour occurs. It looks kinda bug? Ofc, I coded with very bad practice = I was changing my regex on the fly.
Problem with... backtracking? lexical $_ binded to $A?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Strange behaviour when regex variable is modified during match?
by dave_the_m (Monsignor) on Jan 17, 2021 at 19:03 UTC | |
by rsFalse (Chaplain) on Jan 17, 2021 at 20:23 UTC | |
Re: Strange behaviour when regex variable is modified during match?
by Anonymous Monk on Jan 17, 2021 at 19:08 UTC | |
by rsFalse (Chaplain) on Jan 17, 2021 at 20:39 UTC | |
by Anonymous Monk on Jan 18, 2021 at 16:01 UTC | |
Re: Strange behaviour when regex variable is modified during match?
by ikegami (Patriarch) on Jan 18, 2021 at 15:57 UTC | |
Re: Strange behaviour when regex variable is modified during match?
by betmatt (Scribe) on Jan 20, 2021 at 11:25 UTC | |
by rsFalse (Chaplain) on Jan 20, 2021 at 20:50 UTC |
Back to
Seekers of Perl Wisdom