M
Mark
Can someone please explain to me how the redo is affecting the match
results?
Case 1 - without redo:
use strict;
use warnings;
my $bail = 0;
while () {
'ab' =~ /(.)/g;
print "\$1=", defined($1) ? $1 : 'undef', "\n";
last if $bail++ > 5;
# redo;
}
Output:
$1=a
$1=b
$1=b
$1=a
$1=b
$1=b
$1=a
Case 2 - with redo:
use strict;
use warnings;
my $bail = 0;
while () {
'ab' =~ /(.)/g;
print "\$1=", defined($1) ? $1 : 'undef', "\n";
last if $bail++ > 5;
redo;
}
Output:
$1=a
$1=b
$1=undef
$1=a
$1=b
$1=undef
$1=a
It seems to me that redo should have no affect in the second case
below. It appears that when pos is past the end of the string, $1 is
not set in Case 1 but it is reset to undef in Case 2.
results?
Case 1 - without redo:
use strict;
use warnings;
my $bail = 0;
while () {
'ab' =~ /(.)/g;
print "\$1=", defined($1) ? $1 : 'undef', "\n";
last if $bail++ > 5;
# redo;
}
Output:
$1=a
$1=b
$1=b
$1=a
$1=b
$1=b
$1=a
Case 2 - with redo:
use strict;
use warnings;
my $bail = 0;
while () {
'ab' =~ /(.)/g;
print "\$1=", defined($1) ? $1 : 'undef', "\n";
last if $bail++ > 5;
redo;
}
Output:
$1=a
$1=b
$1=undef
$1=a
$1=b
$1=undef
$1=a
It seems to me that redo should have no affect in the second case
below. It appears that when pos is past the end of the string, $1 is
not set in Case 1 but it is reset to undef in Case 2.