Skip to content

Instantly share code, notes, and snippets.

@tokubass
Last active December 12, 2015 09:08
Show Gist options
  • Save tokubass/4748842 to your computer and use it in GitHub Desktop.
Save tokubass/4748842 to your computer and use it in GitHub Desktop.
twitterで見かけたつぶやきに対して。 先頭大文字、全部大文字、全部小文字の3パターンだけに仕様縮小。 もっと短く書きたいなぁ。 ver3
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
my $str = 'foo Foo FOO';
$str =~ s{(foo)}{ my $len = scalar split(/[A-Z]/,$1); ( $len == 0 ) ? 'BAR' : ( $len == 1 ) ? 'bar' : 'Bar' }ieg;
is($str, 'bar Bar BAR');
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment