2020年6月6日土曜日

開発環境

初めてのPerl 第7版 (Randal L. Schwartz(著)brian d foy(著)Tom Phoenix(著)近藤 嘉雪(翻訳)嶋田 健志(翻訳)、オライリージャパン)の14章(文字列処理とソート)、14.5(練習問題)2の解答を求めてみる。

コード

#!/usr/bin/env perl
use strict;
use warnings;
use v5.28;

say "2.";

my %last_name = qw(
    fred  flintstone
    Wilma  Flintstone
    Barney  Rubble
    betty  rubble
    Bamm-Bamm  Rubble
    PEBBLES  FLINTSTONE
);

foreach (sort {lc $last_name{$a} cmp lc $last_name{$b} or
               lc $a cmp lc $b} keys %last_name) {
    say "$last_name{$_}, $_";
}

入出力結果(Zsh、PowerShell、Terminal)

% ./sample2.pl
2.
flintstone, fred
FLINTSTONE, PEBBLES
Flintstone, Wilma
Rubble, Bamm-Bamm
Rubble, Barney
rubble, betty
%

0 コメント:

コメントを投稿