開発環境
- OS X Mavericks - Apple(OS)
- BBEdit - Bare Bones Software, Inc., Emacs (Text Editor)
- Perl (プログラミング言語)
初めてのPerl 第6版 (Randal L. Schwartz (著)、brian d foy (著)、Tom Phoenix (著)、近藤 嘉雪 (翻訳)、オライリージャパン)、14章(文字列処理とソート)の14.5(練習問題)1.を解いてみる。
その他参考書籍
14.5(練習問題)1.
コード(BBEdit, Emacs)
sample304_1.pl
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use 5.016;
binmode STDIN, ':utf8';
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';
my @numbers;
push @numbers, split while <>;
my $cols = 0;
for (@numbers) {
$cols = length $_ if length $_ > $cols;
}
for (sort { $a <=> $b} @numbers) {
printf "%${cols}s\n", $_;
}
入出力結果(Terminal)
$ ./sample304_1.pl < numbers.txt
-10
1.50
1.5
3.14159
04
4
17
666
1000
2001
90210
$ cat numbers.txt
17 1000 04 1.50 3.14159 -10 1.5 4 2001 90210 666
$
0 コメント:
コメントを投稿