I can answer the first for you. m// matches the nothing at any part of the string:
my $target = 'this is a test of the servise';
$target =~ s//are/;
print "$target\n";
There's a spot of nothing at the very start of the string.
I think you're missing /g at the end of the regex in the loop condition. As for that, my assumption is that there's Deep Magic here, and you shouldn't rely on these results.
Another test:
if ($target =~ /test/) {
$target =~ s//quiz/;
}
Maybe a blank regex condition on the left stays with what was previously matched. Dunno if that's an intended feature or not.
Update: I'm upgrading it to potential bug:
my $target = 'this is a test of the servise';
if ($target =~ /test/) {
$target =~ s//test2/;
}
if ($target =~ /nothing/) {
$target = s//null/;
} else {
$target =~ s//foo/;
}
The moral of the story is, don't do a substitution inside a match on the same string. |