rsFalse has asked for the wisdom of the Perl Monks concerning the following question:
Here I used conditionals "(?(condition)yes-pattern|no-pattern)" (perlre).use warnings; use strict; $\ = $/; my $A = 2; my $_0to2 = join '', 0 .. 2; $_ = join '=', ( $_0to2 ) x 2; print "\$_:[$_]"; print /^ \d*(\d)\d* = \d*(\d)\d* (?(?{ my %h; map $h{ $_ } ++, $1, $2; 2 == keys %h }) | (* +FAIL) ) (?(?{ $1 < $2 }) | (*FAIL) ) (?(?{ my $sum = $1 + $2; $sum == $A }) | (*FAIL) ) $/x ? "MATCHED: \$1:[$1], \$2:[$2]" : "NOT_MATCHED" ;
5.18.2 OUTPUT:$_:[012=012] NOT_MATCHED
I haven't understand where is the different behaviour, because I haven't received any warnings by 'use warnings;'.$_:[012=012] MATCHED: $1:[0], $2:[2]
Upd.2:Have swapped versions to correct(?(?{ my %h; map $h{ $_ } ++, $1, $2; print 0 + keys %h; 2 == keys %h +}) | (*FAIL) )
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: 'my' inside /(?{...})/ doesn't refresh a hash variable in 5.14
by LanX (Saint) on Nov 11, 2018 at 16:57 UTC | |
by rsFalse (Chaplain) on Nov 11, 2018 at 17:12 UTC |