開発環境
- OS X Lion - Apple(OS)
- TextWrangler(Text Editor) (BBEditの機能制限無料版、light版)
- Script言語:Perl
『初めてのPerl 第5版』(Randal L. Schwartz, Tom Phoenix, brian d foy 共著、近藤 嘉雪 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-427-9) の4章(サブルーチン), 4.12(練習問題)5を解いてみる。
5.
やり方の1つ。(「やり方は何通りもある」(TIMTOWTDI(There Is More Than One Way To Do It.)))
コード(TextWrangler)
#!/usr/bin/env perl
use strict;
use warnings;
use 5.012;
sub greet{
state @people;
my $name = shift;
if(@people){
print "Hi $name! I've seen : @people\n";
} else {
print "Hi $name! Your are the first one here!\n";
}
push @people, $name;
}
for(qw(Fred Barney Wilma Betty)){
greet($_);
}
入出力結果(Terminal)
$ perl sample.pl Hi Fred! Your are the first one here! Hi Barney! I've seen : Fred Hi Wilma! I've seen : Fred Barney Hi Betty! I've seen : Fred Barney Wilma $
0 コメント:
コメントを投稿