1
0
Fork 0
mirror of https://github.com/perlbot/perlbuut synced 2025-06-07 19:05:50 -04:00

adding the global code, i hope it works right

This commit is contained in:
Ryan Voots 2010-03-12 16:28:54 -05:00
parent 7ece8e935a
commit 2936924a37

View file

@ -334,7 +334,21 @@ sub _fact_substitute
if ($flags =~ /g/)
{
return "Global replacements not coded yet"
my $regex = $flags=~/i/ ? qr/(?i:$match)/i : qr/$match/;
while ($pred =~ /\G$regex/g)
{
my $matchedstring = substr($pred, $-[0], $+[0] - $-[0]);
my ($matchstart, $matchend) = ($-[0], $+[0]);
my @caps = map {substr($pred, $-[$_], $+[$_] - $-[$_])} 1..$#+;
my $realsubst = $subst;
$realsubst =~ s/\$(\d+)/$caps[$1-1]/eg;
substr $pred, $matchstart, $matchend-$matchstart, $realsubst;
pos $pred = $matchstart+length($realsubst); #set the new position, might have an off by one?
}
return "$pred";
}
else
{