perldelta - what is new for perl v5.9.3

switch/smart match と defined-or キタ(・∀・)コレ!!ということで、期待を込めて一部を意訳してみました。恥ずかしながらPerlのrelease engineeringを知らないのですが、5.9系が5.10(もしくは5.8にbackport)としてリリースされると言うことで良いんでしょうか。

あくまで、紹介のためのいい加減な訳ですので、興味を持たれた方はcpanを参照してください。間違っている点、誤解を招く点などあれば、ご指摘ください。

Core Enhancements

The feature pragma

The feature pragma is used to enable new syntax that would break Perl's backwards-compatibility with older releases of the language. It's a lexical pragma, like strict or warnings.

Currently the following new features are available: switch (adds a switch statement), ~~ (adds a Perl 6-like smart match operator), say (adds a say built-in function), and err (adds an err keyword). Those features are described below.

Note that err low-precedence defined-or operator used to be enabled by default (although as a weak keyword, meaning that any function would override it). It's now only recognized when explicitly turned on (and is then a regular keyword).

Those features, and the feature pragma itself, have been contributed by Robin Houston.

Perlの過去のバージョンとの後方互換性を壊す新しい文法を使えるようにする「feature」プラグマを導入しました。

現在は、以下の新機能が利用できます:switch(switch構文)、~~(Perl6の smart match 演算子)、say(組み込み関数 say)、err(errキーワード)。

なお、優先度の低いdefined-od演算子であるerrは、同名の関数があれば上書きされる「weak keyword」として標準で有効となります。

これらの新機能およびfeatureプラグマは、Robin Houston氏の貢献によるものです。

Switch and Smart Match operator

Perl 5 now has a switch statement. It's available when use feature 'switch' is in effect. This feature introduces three new keywords, given, when, and default:

given ($foo) {
when (/^abc/) { $abc = 1; }
when (/^def/) { $def = 1; }
when (/^xyz/) { $xyz = 1; }
default { $nothing = 1; }
}

A more complete description of how Perl matches the switch variable against the when conditions is given in "Switch statements" in perlsyn.

This kind of match is called smart match, and it's also possible to use it outside of switch statements, via the new ~~ operator (enabled via the use feature '~~' directive). See "Smart matching in detail" in perlsyn.

Perl5にswitch構文ができました!この構文は「use feature 'switch' 」により有効化することができ、三つのキーワード given、when、default が追加されます。

when条件節において、どのようにswitch変数をマッチさせるかについては、perlsynのSwitch statementsに書かれています。

この種のマッチは「smart match」と呼ばれ、switch構文以外にも新機能である ~~ 演算子(「use feature '~~' directive」により有効化)からも使うことができます。

say()

say() is a new built-in, only available when use feature 'say' is in effect, that is similar to print(), but that implicitly appends a newline to the printed string. See "say" in perlfunc.

say()は新しい組み込み関数で、「use feature 'say'」により有効となります。文字列を出力した後に改行を加える他は、print()関数と同様です。perlfuncのsayを参照してください。

CLONE_SKIP()

Perl has now support for the CLONE_SKIP special subroutine. Like CLONE, CLONE_SKIP is called once per package; however, it is called just before cloning starts, and in the context of the parent thread. If it returns a true value, then no objects of that class will be cloned. See perlmod for details. (Contributed by Dave Mitchell.)

Perlでは特別なサブルーチンとして CLONE_SKIP に対応しました。CLONE と同様に、CLONE_SKIP もパッケージ毎に一度だけ呼ばれますが、親スレッドのコンテキストにおいて、cloning start の前にも呼ばれます。真の値を返した場合にはどのオブジェクトもcloneされていません。詳しくはperlmodを参照してください。(Dave Mitchell氏の貢献によるものです)

${^CHILD_ERROR_NATIVE}

A new internal variable, ${^CHILD_ERROR_NATIVE}, gives the native status returned by the last pipe close, backtick command, successful call to wait() or waitpid(), or from the system() operator. See perlrun for details. (Contributed by Gisle Aas.)

新しい内部変数「${^CHILD_ERROR_NATIVE}」では、最後に実行された以下の native status を保持します。

  • the last pipe close
  • backtick command
  • successful call to wait() or waitpid()
  • the system() operator

詳しくはperlrunを参照してください。(Gisle Aas氏の貢献によるものです)

Assertions

The support for assertions, introduced in perl 5.9.0, has been improved. The syntax for the -A command-line switch has changed; it now accepts an optional module name, defaulting to assertions::activate. See assertions and perlrun. (Contributed by Salvador Fandino Garcia.)

perl 5.9.0以降のassertionsが改善されました。コマンドラインの -A は、optional module name を受け付けるように変更されました。標準ではassertions::activateが利用されます。詳しくはassertionsおよびperlrunを参照してください。(Salvador Fandino Garcia氏の貢献によるものです)

Unicode Character Database 4.1.0

The copy of the Unicode Character Database included in Perl 5.9 has been updated to 4.1.0.

Perl5.9に含まれるUnicode Character Databaseが4.1.0に更新されました。

no VERSION

You can now use no followed by a version number to specify that you want to use a version of perl inferior to the specified one.

指定したものより以前のバージョンのPerlを要求するために、バージョン番号の前に「no」を加えることができるようになりました。

Recursive sort subs

You can now use recursive subroutines with sort(), thanks to Robin Houston.

sort()に再帰的なサブルーチンを利用できるようになりました。thanks to Robin Houston.

Effect of pragmas in eval

The compile-time value of the %^H hint variable can now propagate into eval("")uated code. This makes it more useful to implement lexical pragmas.

As a side-effect of this, the overloaded-ness of constants now propagates into eval("").

コンパイル時のヒント変数 %^H は、evalu("")により評価されます。これにより、より便利な字句的なプラグマを実装できるようになります。

この副作用として、オーバーロードされた定数もeval("")により評価されるようになります。

New -E command-line switch
  • E is equivalent to -e, but it implicitly enables all optional features (like use feature ":5.10").
  • E は -e と同様ですが、明示的に追加機能を有効化します(例: use like feature ":5.10")。
chdir, chmod and chown on filehandles

chdir, chmod and chown can now work on filehandles as well as filenames, if the system supports respectively fchdir, fchmod and fchown, thanks to a patch provided by Gisle Aas.

fchdir、fchmod、fchownに対応しているシステムでは、chdir、chmod、chownはファイル名だけでなくファイルハンドルに対しても有効となりました。パッチ提供者の Gisle Aas に感謝します。

OS groups

$( and $) now return groups in the order where the OS returns them, thanks to Gisle Aas. This wasn't previously the case.

$(および$)では、OSが返した順にグループを返します。

Modules and Pragmata

New Core Modules
  • A new pragma, feature, has been added; see above in "Core Enhancements".
  • assertions::compat, also available on CPAN, allows the use of assertions on perl versions prior to 5.9.0 (that is the first one to natively support them).
  • Math::BigInt::FastCalc is an XS-enabled, and thus faster, version of Math::BigInt::Calc.
  • Compress::Zlib is an interface to the zlib compression library. It comes with a bundled version of zlib, so having a working zlib is not a prerequisite to install it. It's used by Archive::Tar (see below).
  • IO::Zlib is an IO::-style interface to Compress::Zlib.
  • Archive::Tar is a module to manipulate tar archives.
  • Digest::SHA is a module used to calculate many types of SHA digests, has been included for SHA support in the CPAN module.
  • 新しいプラグマ feature が追加されました。Core Enhancementsに書かれています。
  • CPAN からも入手できる assertions::compat により、5.9.0 以前と同様のアサーションが利用できます。
  • Math::BigInt::FastCalc は Math::BigInt::Cals のXS版で、より高速に動作します。
  • Compress::Zlib は zlib 圧縮ライブラリへのインターフェースです。これは bundle された zlib を利用するため、インストールには既に動いている zlib を要求しません。以下の Archive::Tar から利用されます。
  • IO::Zlib は Compress::Zlib を IO::形式にしたものです。
  • Archive::Tar は tar アーカイブを操作するモジュールです。
  • Digest::SHA は様々な形式の SHA ダイジェストを求めるモジュールです。CPANモジュールのSHA対応に含まれます。