開発環境
- OS X Lion - Apple(OS)
- TextWrangler(Text Editor) (BBEditの機能制限無料版、light版)
- Script言語:Perl
『続・初めてのPerl 改訂版』(Randal L. Schwartz, brian d foy, Tom Phoenix 著、伊藤 直也、田中 慎司、吉川 英興 監訳、株式会社ロングテール/長尾 高弘 訳、オライリー・ジャパン、2006年、ISBN4-87311-305-9) の9章(リファレンスを使った実践的なテクニック), 9.9(練習問題)3を解いてみる。
3.
やり方の1つ。(「やり方は何通りもある」(TIMTOWTDI(There Is More Than One Way To Do It.)))
コード(TextWrangler)
#!/usr/bin/env perl
use strict;
use warnings;
my @list = qw(e a d b c E A D B C);
my @sorted =
map $_->[0],
sort {$a->[1] cmp $b->[1]}
map {
my $string = $_;
$string =~ tr/A-Z/a-z/;
$string =~ tr/a-z//cd;
[$_, $string];
} @list;
print "リスト: @list\n";
print "辞書順: @sorted\n";
入出力結果(Terminal)
$ perl sample.pl リスト: e a d b c E A D B C 辞書順: a A b B c C d D e E $
0 コメント:
コメントを投稿