Created
December 15, 2016 03:51
-
-
Save azumakuniyuki/69cb6ca3ca762148ff09147bbffdef17 to your computer and use it in GitHub Desktop.
Perl入学式2016年第4回の練習問題+「ニャーン」改1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
while( chomp(my $input = <STDIN>) ) { | |
# 入力された文字を判定 | |
last if $input eq '0'; | |
# 文字列の内容によって書き換える | |
print 'Find Perl!'."\n" if $input =~ m/[Pp]erl/; | |
print 'Find Python!'."\n" if $input =~ m/python/i; | |
print 'Love Programming!'."\n" if $input =~ m/(?:perl|ruby|python)/; | |
print 'Find papix!'."\n" if $input =~ m/\Apapix/; | |
print 'Hello! '.$1.'!'."\n" if $input =~ m/Hello\s*(.+)\z/; | |
if( $input =~ m/\A(.+)。/ ) { | |
my $text = $1; | |
my $maru = '。'; | |
if( $text =~ m/[にニ][ゃャ]ー*[んン]?/ ) { | |
# 。より前のニャーンは書き換えない | |
print $text.$maru."\n"; | |
} else { | |
# にゃーんが含まれない文字列 | |
if( $text =~ m/(.*)(モーニング娘)(.*)/ ) { | |
# モーニング娘。 | |
$text = $1.$2.$maru.$3; | |
} | |
print $text.nyaan().$maru."\n"; | |
} | |
} else { | |
print '「にゃーん?」'."\n" | |
} | |
} | |
sub nyaan { | |
# ニャーとかニャーーーーを返す | |
my $nyaa = 'ニャ'; | |
my $dash = 'ー' x int(rand(9)); | |
return $nyaa.$dash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment