내가 제대로 작동하지 못하는 부분은 항상 실패하기 때문에 조건부입니다.
use Test::More tests => 2;
my $regex = qr/(\d+),(\d+)
(?(?{\g1<\g2})(*FAIL))
/x ;
like( "(23,36)", $regex, 'should match' );
unlike( "(36,23)", $regex, 'should not match' );
not ok 1 - should match
# Failed test 'should match'
# at - line 7.
# '(23,36)'
# doesn't match '(?^x:(\d+),(\d+)
# (?(?{\g1<\g2})(*FAIL))
# )'
ok 2 - should not match
# Looks like you failed 1 test of 2.
코드에 다음 수정 사항이 필요합니다.
$1
및 $2
변수를 사용합니다 (?{ })
.(*SKIP)
역 추적을 명시 적으로 방지 하려면 제어 동사를 사용하십시오 .코드:
use strict;
use warnings;
use Test::More tests => 2;
my $regex = qr/(\d+),(\d+)
(?(?{$1 > $2})(*SKIP)(*FAIL))
/x ;
like( "(23,36)", $regex, 'should match' );
unlike( "(36,23)", $regex, 'should not match' );
출력 :
1..2
ok 1 - should match
ok 2 - should not match
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다