2012年5月15日火曜日

開発環境

『初めてのPerl 第5版』(Randal L. Schwartz, Tom Phoenix, brian d foy 共著、近藤 嘉雪 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-427-9) の3章(リストと配列), 3.10(練習問題)3を解いてみる。

3.

全ての文字列を1行にも、別々の行にも、どちらのスタイルでも出力、表示できる。

やり方の1つ。(「やり方は何通りもある」(TIMTOWTDI(There Is More Than One Way To Do It.)))

コード(TextWrangler)

#!/usr/bin/env perl
use strict;
use warnings;

print "1行に表示\n";
chomp(my @strings = <STDIN>);
my @sorted = sort @strings;
print "@sorted\n";
print "別々の行に表示\n";
print sort <STDIN>;

入出力結果(Terminal)

$ perl sample.pl
1行に表示
fred
barney
wilma
betty
barney betty fred wilma
別々の行に表示
fred
barney
wilma
betty
barney
betty
fred
wilma
$

0 コメント:

コメントを投稿