Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

colomon (8994)

  (email not shown publicly)

Journal of colomon (8994)

Monday March 02, 2009
02:04 PM

Improved Version of Last Script

[ #38579 ]
New version handles my standard "trimmed_surface" becomes "TrimmedSurface" convention, and has a rather more elegant main loop.

my $search_word = @*ARGS.shift;
my $replacement = @*ARGS.shift;

sub UpperCaseEachWord($word)
    my @words = $word.split('_');
    my @uppered = map {$}, @words;
    return @uppered.join('');

my %substitutions;
%substitutions{$} = $;
%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;

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.