Hi all,
I'm learning Perl and noticed a rather peculiar quirk -- attempting to match one of multiple regex conditions in a while loop results in that loop going on for infinity:
#!/usr/bin/perl
my $hivar = "this or that";
while ($hivar =~ m/this/ig || $hivar =~ m/that/ig) {
print "$&\n";
}
The output of this program is:
this
that
that
that
that
[...]
I'm wondering why this is? Are there any workarounds that are less clumsy than this:
#!/usr/bin/perl
my $hivar = "this or that";
while ($hivar =~ m/this|that/ig) {
print "$&\n";
}
This is a simplification of a real-world problem I am encountering, and while I am interested in this in a practical standpoint, I also would like to know what behind-the-scenes is triggering this behavior. This is a question that doesn't seem to be very Google-compatible.
Thanks!
Tom