Skip to content

Instantly share code, notes, and snippets.

@colomon
Created May 13, 2009 17:24
Show Gist options
  • Select an option

  • Save colomon/111141 to your computer and use it in GitHub Desktop.

Select an option

Save colomon/111141 to your computer and use it in GitHub Desktop.
#!~/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 $*IN.lines() -> $text is rw
{
for %substitutions.pairs -> $sub
{
$text .= subst($sub.key, $sub.value, :g);
}
say $text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment