If getting the right case is important, some extra steps may be needed. I think this version of replaceword() would be sufficient, as either lowercase or ucfirst() would be the normal casing. All-uppercase as a default disallows strange mixed case renderings, so while it would preserve some effect, it's still not a complete solution.
sub replaceword {
my $w = $_[0];
my $repl = $bad_words{ lc( $w ) };
$repl = ucfirst( $repl ) if ( $w =~ /^[A-Z]/ );
return $repl;
}
Of course, this would require that the eval flag stay on the substitution in my previous post, contrary to the update which applies to the code as appears in that node.
| [reply] [d/l] |
Yeah, I thought about something that would map case letter by letter, wrapping around if the replacement word were longer, but decided that leaving it uppercase was good enough. I didn't really think if uppercase as the default, since I would expect almost all cases to be lower or ucfirst as you say, but as a fallback for weird case (or actual uppercase input).
| [reply] |