開発環境
- 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) の14章(文字列処理とソート), 14.5(練習問題)2を解いてみる。
2.
やり方の1つ。(「やり方は何通りもある」(TIMTOWTDI(There Is More Than One Way To Do It.)))
コード(TextWrangler)
#!/usr/bin/env perl use strict; use warnings; my %last_name = qw{ fred flintstone Wilma Flintstone Barney Rubble betty rubble Bamm-Bamm Rubble PEBBLES FLINTSTONE }; my @keys = sort{ "\L$last_name{$a}" cmp "\L$last_name{$b}" or "\L$a" cmp "\L$b" } keys %last_name; for(@keys){ print "$last_name{$_}, $_\n"; }
入出力結果(Terminal)
$ perl perl_program flintstone, fred FLINTSTONE, PEBBLES Flintstone, Wilma Rubble, Bamm-Bamm Rubble, Barney rubble, betty $
0 コメント:
コメントを投稿