perl 5.13.7がリリースされた*1。このバージョンは革新的な新機能を搭載しており、新時代のPerlといっても過言ではないものとなっている。
それが以下の機能である。
Array and hash container functions accept references
All built-in functions that operate directly on array or
hash containers now also accept hard references to arrays
or hashes:
|----------------------------+---------------------------|
| Traditional syntax | Terse syntax |
|----------------------------+---------------------------|
| push @$arrayref, @stuff | push $arrayref, @stuff |
| unshift @$arrayref, @stuff | unshift $arrayref, @stuff |
| pop @$arrayref | pop $arrayref |
| shift @$arrayref | shift $arrayref |
| splice @$arrayref, 0, 2 | splice $arrayref, 0, 2 |
| keys %$hashref | keys $hashref |
| keys @$arrayref | keys $arrayref |
| values %$hashref | values $hashref |
| values @$arrayref | values $arrayref |
| ($k,$v) = each %$hashref | ($k,$v) = each $hashref |
| ($k,$v) = each @$arrayref | ($k,$v) = each $arrayref |
|----------------------------+---------------------------|
This allows these built-in functions to act on long
dereferencing chains or on the return value of subroutines
without needing to wrap them in @{} or %{}:
push @{$obj->tags}, $new_tag; # old way
push $obj->tags, $new_tag; # new way
for ( keys %{$hoh->{genres}{artists}} ) {...} # old way
for ( keys $hoh->{genres}{artists} ) {...} # new way つまり、コンテナ型のデリファレンスは、多くのケースでシジルが必要なくなったのだ!
これにより煩雑だったリファレンスの扱いが非常に単純になり、プログラミングも楽になるに違いない。
Perl 5.12はメジャーリリースとはいえ新機能はごく少なく、内部構造の整理が主だった。しかしPerl 5.14は今回の新機能のみならず、s///r (non-destructive substitution)やpackage BLOCK syntaxなどの興味深い新機能が目白押しとなっている。これは正規リリースが非常に楽しみだ。
*1:追記:5.13.xは5.14へ向けた開発版である。