나는 다소 독특한 특질을 펄을 배우고 발견 해요 - 무한 동안 계속 그 루프 while 루프 결과에 여러 정규식 조건 중 하나와 일치를 시도 :Perl : while 전역에서 "또는"분리 된 정규식 조건으로 인해 무한 루프가 발생합니까?
이#!/usr/bin/perl
my $hivar = "this or that";
while ($hivar =~ m/this/ig || $hivar =~ m/that/ig) {
print "$&\n";
}
이 프로그램의 출력입니다 :
this
that
that
that
that
[...]
이유가 궁금합니다.
#!/usr/bin/perl
my $hivar = "this or that";
while ($hivar =~ m/this|that/ig) {
print "$&\n";
}
이 제가 발생하고 실제 문제의 단순화, 그리고 내가 실용적인 관점에서이에 관심이있는 동안, 나는 또한 알고 싶습니다이보다 적은 서투른있는 대안이 있습니까 그 뒤에 무엇이이 행동을 촉발시키고 있는지. Google과 호환되지 않는 질문입니다.
감사합니다.
톰
홉스 (hobbes)가 아래에서 잘 설명했지만 Wall, Schwartz 등이 이에 대해서도 설명했습니다. http://perldoc.perl.org/perlretut.html#Global-matching – msw
Regexp :: 패키지를 조립하면 도움이됩니다. http://stackoverflow.com/questions/1478083/how-can-i-efficiently-match-many-different-regex-patterns-in-perl –