開発環境
- OS X Mavericks - Apple(OS)
- BBEdit - Bare Bones Software, Inc., Emacs (Text Editor)
- Perl (プログラミング言語)
初めてのPerl 第6版 (Randal L. Schwartz (著)、brian d foy (著)、Tom Phoenix (著)、近藤 嘉雪 (翻訳)、オライリージャパン)、4章(サブルーチン)の4.12(練習問題)1を解いてみる。
その他参考書籍
1.
コード(BBEdit, Emacs)
sample.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';
sub total {
my $result = 0;
for (@_) {
$result += $_;
}
$result;
}
my @fred = qw( 1 3 5 7 9);
my $fred_total = total(@fred);
say "The total of \@fred is $fred_total.";
print 'Enter some numbers on seprate lines: ';
my $user_total = total(<STDIN>);
say "The total of those numbers is $user_total.";
入出力結果(Terminal)
$ ./sample.pl The total of @fred is 25. Enter some numbers on seprate lines: 1 2 3 4 5 6 7 8 9 10 The total of those numbers is 55. $
0 コメント:
コメントを投稿