Perl/SortUnicode

  • Search
  • Home
  • All
  • Files
  • History
  • Latest Changes

Perl

  • Amazon
  • EPSファイル作成
  • ApacheErrorLogFormatter
  • AutoHashedFuncs
  • CGI.pm
  • compareXML
  • CPAN
  • createUniqKeyList
  • DBIx-Custom
  • DBIx-NamedParams
  • decodeQuotedPrintable
  • EscapeSlash
  • GD
  • getDiskUsage
  • getHostName
  • GMTtoLocalTime
  • GoogleMapAPI
  • HostToIP
  • HttpHeader
  • HTTPアクセス
  • initConsole
  • IPアドレス範囲をマスク表現に変換
  • ListDownloader
  • MailForm
  • makeCodeHighlightKeyword
  • MatchList
  • MSSQL_ImpExp
  • MySQL-BIT
  • NetWatcher
  • nicoget
  • Object-Simple
  • packBit
  • Perl-Tidy
  • readXSV
  • SHA1
  • SortUnicode
  • updateEarth
  • W03_FOMA
  • WhoisGW
  • Windows_DLL_Call
  • XML-Simple
  • XML-XPath
  • YAML
  • オブジェクト指向プログラミング
  • キーワード置換
  • ディレクトリの再帰処理
  • ファイルの一括処理
  • ファイル名正規化
  • 全角から半角へ変換
  • 参照
  • 多次元配列
  • 文字コード
  • 日経ITpro
  • 曜日の計算(Zellerの公式)
  • 未定義コード置換
  • 特殊文字のエスケープ
  • 環境変数
  • 自動フラッシュ(バッファリング)の制御
  • 行末改行の削除

Table of Contents
  • 概要
  • ソース
  • 出力
  • リンク

概要

  • Unicode 順でのソート。
  • ひらがな/カタカナを区別せずにソートするには「Unicode::Collate」でソートする。

ソース

  • sortUnicode.zip
    #!/usr/bin/perl
    # Unicode 順のソート
    
    use strict;
    use warnings;
    use utf8;
    use Encode;
    use POSIX qw(locale_h);
    use locale;
    use Unicode::Collate;
    
    my $charsetConsole = 'UTF-8';
    
    binmode( STDIN,  ":encoding($charsetConsole)" );
    binmode( STDOUT, ":encoding($charsetConsole)" );
    binmode( STDERR, ":encoding($charsetConsole)" );
    
    my @list = split( //, 'あぁAAアアaはばぱがかぴひび' );
    
    my $locale = "ja_JP.UTF-8";
    setlocale( LC_ALL, $locale );
    print "locale($locale)\n";
    print join( "", sort(@list) ) . "\n";
    print "\n";
    my $Collator = Unicode::Collate->new();
    print "Unicode::Collate\n";
    print join( "", $Collator->sort(@list) ) . "\n";

出力

  • Cent OS 6, perl v5.10.1
    locale(ja_JP.UTF-8)
    AaアAぁあかがはばぱひびぴア
    
    Unicode::Collate
    aAAぁあアアかがはばぱひびぴ

リンク

  • CPAN:Unicode-Collate
  • Perl のロケール操作 (国際化と地域化)

Home

Last edited by TakeAsh, 2018-09-01 01:15:27