New version handles my standard "trimmed_surface" becomes "TrimmedSurface" convention, and has a rather more elegant main loop.
#!/Users/colomon/tools/rakudo/perl6 my $search_word = @*ARGS.shift; my $replacement = @*ARGS.shift;
sub UpperCaseEachWord($word) { my @words = $word.split('_'); my @uppered = map {$_.lc.ucfirst}, @words; return @uppered.join(''); }
my %substitutions; %substitutions{$search_word.lc} = $replacement.lc; %substitutions{$search_word.uc} = $replacement.uc; %substitutions{UpperCaseEachWord($search_word)} = UpperCaseEachWord($replacement);
# for %substitutions.pairs -> $x # { # say "{$x.key}, {$x.value}"; # }
for =$*IN -> $text is rw { for %substitutions.pairs -> $sub { $text .= subst($sub.key, $sub.value, :g); } say $text; }