From 08353422461d4f471f5b6076988ba44ac59f12c4 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sat, 22 Feb 2020 07:19:43 -0800 Subject: [PATCH] Plugins/TypoSub: be more intelligent about replacing \1 and $1 thingies --- Plugins/TypoSub.pm | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/Plugins/TypoSub.pm b/Plugins/TypoSub.pm index 7476dd25..cb56fe2a 100644 --- a/Plugins/TypoSub.pm +++ b/Plugins/TypoSub.pm @@ -74,15 +74,23 @@ sub on_public { else { $result = "$nick thinks $target meant to say: "; } my $text = $message->{msg}; if ($modifiers =~ m/g/) { - $text =~ s/$rx/$replacement/g; - my @stuff = ($1, $2, $3, $4, $5, $6, $7, $8, $9); - my $i; - map { ++$i; $text =~ s/[\$\\]$i/$_/g; } @stuff; + $text =~ s{$rx} + { + my @stuff = ($1, $2, $3, $4, $5, $6, $7, $8, $9); + my $t = $replacement; + my $i = 0; + defined $_ // last, ++$i, $t =~ s|[\$\\]$i|$_|g for @stuff; + $t + }gxe; } else { - $text =~ s/$rx/$replacement/; - my @stuff = ($1, $2, $3, $4, $5, $6, $7, $8, $9); - my $i; - map { ++$i; $text =~ s/[\$\\]$i/$_/g; } @stuff; + $text =~ s{$rx} + { + my $i = 0; + my @stuff = ($1, $2, $3, $4, $5, $6, $7, $8, $9); + my $t = $replacement; + defined $_ // last, ++$i, $t =~ s|[\$\\]$i|$_|g for @stuff; + $t + }xe; } $event->{conn}->privmsg($channel, "$result$text"); return 0;