開発環境
- OS X Mavericks - Apple(OS)
- BBEdit - Bare Bones Software, Inc., Emacs (Text Editor)
- Perl (プログラミング言語)
初めてのPerl 第6版 (Randal L. Schwartz (著)、brian d foy (著)、Tom Phoenix (著)、近藤 嘉雪 (翻訳)、オライリージャパン)、15章(スマートマッチとgiven-when)の15.6(練習問題)2.を解いてみる。
その他参考書籍
15.6(練習問題)2.
コード(BBEdit, Emacs)
fizz_buzz.pl
#!/usr/bin/env perl # use diagnostics; use strict; use warnings; use 5.016; use utf8; binmode STDIN, ':utf8'; binmode STDOUT, ':utf8'; binmode STDERR, ':utf8'; for (1..105) { print "$_: "; given ($_) { when (not $_ % 3) {print 'Fizz '; continue;} when (not $_ % 5) {print 'Bin '; continue;} when (not $_ % 7) {print 'Sausage';} } say ''; }
入出力結果(Terminal)
$ ./fizz_buzz.pl 1: 2: 3: Fizz 4: 5: Bin 6: Fizz 7: Sausage 8: 9: Fizz 10: Bin 11: 12: Fizz 13: 14: Sausage 15: Fizz Bin 16: 17: 18: Fizz 19: 20: Bin 21: Fizz Sausage 22: 23: 24: Fizz 25: Bin 26: 27: Fizz 28: Sausage 29: 30: Fizz Bin 31: 32: 33: Fizz 34: 35: Bin Sausage 36: Fizz 37: 38: 39: Fizz 40: Bin 41: 42: Fizz Sausage 43: 44: 45: Fizz Bin 46: 47: 48: Fizz 49: Sausage 50: Bin 51: Fizz 52: 53: 54: Fizz 55: Bin 56: Sausage 57: Fizz 58: 59: 60: Fizz Bin 61: 62: 63: Fizz Sausage 64: 65: Bin 66: Fizz 67: 68: 69: Fizz 70: Bin Sausage 71: 72: Fizz 73: 74: 75: Fizz Bin 76: 77: Sausage 78: Fizz 79: 80: Bin 81: Fizz 82: 83: 84: Fizz Sausage 85: Bin 86: 87: Fizz 88: 89: 90: Fizz Bin 91: Sausage 92: 93: Fizz 94: 95: Bin 96: Fizz 97: 98: Sausage 99: Fizz 100: Bin 101: 102: Fizz 103: 104: 105: Fizz Bin Sausage $
0 コメント:
コメントを投稿