重要なお知らせ

「教えて! goo」は2025年9月17日(水)をもちまして、サービスを終了いたします。詳細はこちら>

【GOLF me!】初月無料お試し

お世話になります。
Unicodeの文字プロパティの使い方を学ぶために、以下のようなスクリプトをUTF-8で保存しました。

============
#! /bin/perl
#
# utf8_unireg.pl

use 5.010;
use strict;
use warnings;
use utf8;
binmode STDOUT, ":encoding(shift_jis)";

my $str = "a:b:c:";

say join "|", ($str =~ /\p{ASCII}/g);
say join "|", ($str =~ /\p{AsciiAlpha}/g);


sub AsciiAlpha {
return <<END;
0041005A# A-Z
0061007A# a-z
END
}
============

実行するとこうなります。

============
C:\Perl\perl>utf8_unireg2.pl
a|:|b|:|c|:
Can't find Unicode property definition "AsciiAlpha" at C:\Perl\perl\utf8_unireg2.pl line 14.
============

\p{AsciiAlpha}というプロパティの作成に失敗しているようです。。
なぜか分かりますでしょうか?
よろしくお願いします。

A 回答 (2件)

http://perldoc.jp/docs/perl/5.12.1/perlunicode.p …

上記を読みながら、書いてみた例。
「Perl:Unicodeプロパティ作れな」の回答画像1
    • good
    • 0
この回答へのお礼

ありがとうございます!
自作プロパティの場合IsまたはInが必要なんですね。

これ、5.12のときはIs、Inがなくてもできたようです。



C:\Perl\perl>type utf8_unireg2.pl
#! /bin/perl
#
# utf8_unireg.pl

use 5.010;
use strict;
use warnings;
use utf8;
binmode STDOUT, ":encoding(shift_jis)";

my $str = "a:b:c:";

say join "|", ($str =~ /\p{AsciiAlpha}/g);


sub AsciiAlpha {
return <<END;
0041 005A # A-Z
0061 007A # a-z
END
}

C:\Perl\perl>perl utf8_unireg2.pl
a|b|c

C:\Perl\perl>perl -v

This is perl 5, version 12, subversion 1 (v5.12.1) built for MSWin32-x86-multi-thread

Copyright 1987-2010, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.


C:\Perl\perl>



ところが、5.16になってからは、(Is|In)が必要になったようです。



C:\Perl\perl>perl -v

This is perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2012, Larry Wall

Binary build 1603 [296746] provided by ActiveState http://www.ActiveState.com
Built Mar 13 2013 11:29:21

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.


C:\Perl\perl>type utf8_unireg2.pl
#! /bin/perl
#
# utf8_unireg.pl

use 5.010;
use strict;
use warnings;
use utf8;
binmode STDOUT, ":encoding(shift_jis)";

my $str = "a:b:c:";

say join "|", ($str =~ /\p{AsciiAlpha}/g);


sub AsciiAlpha {
return <<END;
0041 005A # A-Z
0061 007A # a-z
END
}

C:\Perl\perl>perl utf8_unireg2.pl
Can't find Unicode property definition "AsciiAlpha" at utf8_unireg2.pl line 13.

C:\Perl\perl>type utf8_unireg2.pl
#! /bin/perl
#
# utf8_unireg.pl

use 5.010;
use strict;
use warnings;
use utf8;
binmode STDOUT, ":encoding(shift_jis)";

my $str = "a:b:c:";

say join "|", ($str =~ /\p{IsAsciiAlpha}/g);


sub IsAsciiAlpha {
return <<END;
0041 005A # A-Z
0061 007A # a-z
END
}

C:\Perl\perl>perl utf8_unireg2.pl
a|b|c



昔動いたプログラムが動かなくなったので、Perlの仕様変更でしょうね。。

ありがとうございました。

お礼日時:2013/07/08 00:49

仕様としては, 5.10 のときでも「In」または「Is」で始まることが必要だったようです.



実装としていつ「In」または「Is」を要求するようになったのかは探せていませんが.

参考URL:http://perldoc.perl.org/5.10.0/perlunicode.html# …
    • good
    • 0
この回答へのお礼

ありがとうございます!
なるほどー。

お礼日時:2013/07/08 18:51

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!