Perl5.12.0の新機能
http://perldoc.perl.org/5.12.0/perl5120delta.html
とりあえず、押さえておいた方が良さそうなものをチョイスです。
colinux(Debian/Lenny)でコンパイル/インストールしたものを使ってみました。
Yada Yada Operator
Blah-Blah-Blahのような演算子(?)。あとでコード埋めるけど、今は"..."置いておくか。みたいな感じで使うのでしょう(きっと)。
$ perl -e '...;' Unimplemented at -e line 1.
微妙かも。
Y2038 compliance
2038年問題をクリア。「あなたにはあまり意味は無いかもしれないが、子供たちは望むだろう!」とのことです。
独身ですけど?(そこか)
$ perl -e 'print scalar localtime(4502271600), qq{\n}' Sat Sep 3 00:00:00 2112
ドラえもんも安心。
Pluggable keywords
This allow a completely non-Perl sublanguage to be parsed inline, with the correct ops cleanly generated.
Perlの言語を拡張する機能のようです。非Perlの言語をインラインで埋め込んでパーザに通すことが可能になる模様です。実験的位置づけで、5.14でどうするか判断されるとのこと。
\N experimental regex escape
\Nは(\n)以外の文字をあらわします。\Nで一文字、\N{n}でn文字毎にまとめてマッチし、\N{m,n}で、最長n文字、最短m文字毎にまとめてマッチするようです。これに伴い、\N{NAME}のカスタム文字名は、きちんと名前をつけてくださいとのこと。
my $d = "London_bridge_is_falling_down.\n"; while($d =~ /\G(\N{7})/gs){ print "$1 "; } print "\n"; while($d =~ /\G(\N{1,7})/gs){ print "$1 "; } print "\n";
London_ bridge_ is_fall ing_dow London_ bridge_ is_fall ing_dow n.
Perlらしい機能かも。
each is now more flexible
eachが配列に対して使用可能になりました。
my @list = (0, 1, 4, 1, 2, 9, 8, 3); while(my ($k, $v) = each @list){ print "$k:$v "; } print "\n"; print "@list\n";
0:0 1:1 2:4 3:1 4:2 5:9 6:8 7:3 0 1 4 1 2 9 8 3
今更な気がしないでも無いですが、嬉しい機能です。
REGEXPs are now first class
Internally, Perl now treates compiled regular expressions (such as those created with qr//) as first class entities. Perl modules which serialize, deserialize or otherwise have deep interaction with Perl's internal data structures need to be updated for this change. Most affected CPAN modules have already been updated as of this writing.
Perl内部で、(qr//で作成されたような)正規表現がファーストクラスエンティティとして扱われます。Perlモジュールは、デシリアライズ・シリアライズするか、Perlの内部データ構造に深く干渉するように、変更する必要があります。影響を受ける大部分のCPANモジュールは既に修正されています。
よく分からないです。PurePerlなら関係なし?
Switch関連
use Switchが非推奨になりました。use feature "switch"を使えということらしいです。whenでflip-flop演算子("..")やら("//")が使えるようになりました。
その他
ファイルハンドル
ファイルハンドルはIO::Fileオブジェクトが使われることになったようです。
こっちはOK。便利。(use IO::File;
必須)
use IO::File; open(my $fh, '<', '...') or die $!; print $fh->getlines; $fh->close;
こっちはNG。仕方が無い?use IO::File;
を付ければOKでした。
use IO::File; my $str = "Hello\nWorld!"; open(my $fh, '<', \$str) or die $!; print $fh->getlines; $fh->close;
length undef
length undef
の返値が0からundefに変更されました。地味に影響が出るかも知れません。
$ perl -MData::Dumper -e 'print Dumper(length undef)' $VAR1 = undef;