My First Useful Perl 6 Script!

colomon on 2009-02-22T11:26:52

I wanted to extend TextMate to do a case-aware search-and-replace. I decided to try it in Perl 6 because I wanted to use the :samecase modifier. Unfortunately, I was not able to get :samecase to work, but a simple modification made the script equally useful for me. I know this is mind-bogglingly simple, but it's now a practical part of my development environment for work.

#!/Users/colomon/tools/parrot-latest/languages/rakudo/perl6
my $search_word = @*ARGS.shift;
my $replacement = @*ARGS.shift;

for =$*IN -> $x { my $y = $x.subst($search_word.lc, $replacement.lc, :g); my $z = $y.subst($search_word.uc, $replacement.uc, :g); say $z.subst($search_word.lc.ucfirst, $replacement.lc.ucfirst, :g); }
I'll probably tweak this with some further improvements, including one that :samecase couldn't have handled anyway. But I just wanted to celebrate my first practical Perl 6 script!


Names!

jplindstrom on 2009-02-22T16:10:40

$x, $y, $z?

Really?

Re:Names!

colomon on 2009-02-22T20:44:01

Eh, might be pathetic, but for a straightforward seven line script it's good enough. I wouldn't have used anything but $x if $x hadn't been read-only.

I'm pondering making it about twice as complicated, and if I do, there will be better variable names, I promise.