perl5.10新特性
2010-04-16 21:56:13 阿炯

Today the Perl Foundation announces the release of Perl 5.10, the first major upgrade to the wildly popular dynamic programming language in over five years. This latest version builds on the successful 5.8.x series by adding powerful new language features and improving the Perl interpreter itself. The Perl development team, called the Perl Porters, has taken features and inspiration from the ambitious Perl 6 project, as well as from chiefly academic languages and blended them with Perl's pragmatic view to practicality and usefulness.

Perl 基金会公布了 Perl 的5.10版本,该版本是这个广为流行的动态语言五年多来的首次主要升级。最新的版本不仅在已经非常成功的5.8.x的基础上添加了强大的新功能,而且对 Perl 解释器本身也进行了改进。Perl的开发团队,即 Perl Porters,从雄心勃勃的 Perl 6项目,以及其他的主要流行语言中,吸取了特性和灵感,并将它们融入了 Perl 语言实用为上的理念之中。

Significant new language features
The most exciting change is the new smart match operator. It implements a new kind of comparison, the specifics of which are contextual based on the inputs to the operator. For example, to find if scalar $needle is in array @haystack, simply use the new ~~ operator:

if ( $needle ~~ @haystack ) ...

The result is that all comparisons now just Do The Right Thing, a hallmark of Perl programming. Building on the smart-match operator, Perl finally gets a switch statement , and it goes far beyond the kind of traditional switch statement found in languages like C, C++ and Java.

显著的新语言特性
最令人兴奋的改进是全新的智能匹配操作符(smart match operator) 。该操作符实现了一种全新的比较方式,而其具体作用是随操作符接受的输入而有所不同的。举例而言,要看标量 $needle 是否存在于数组 @haystack 中,只要使用新的 ~~ 操作符:

if ( $needle ~~ @haystack ) ...

其结果将会"正如你所愿",而这正是 Perl 语言一贯的标志性做法。在此操作符的基础之上,Perl 语言终于有了 switch 语句 ,而且它比任何传统的 switch 语句,像 C,C++ 和 JAVA 拥有的那些,要先进得多。

Regular expressions are now far more powerful. Programmers can now use named captures in regular expressions, rather than counting parentheses for positional captures. Perl 5.10 also supports recursive patterns, making many useful constructs, especially in parsing, now possible. Even with these new features, the regular expression engine has been tweaked, tuned and sped up in many cases.

正则表达式也变得更加强大了。程序员们现在可以在正则表达式中使用用命名的捕获变量 (named captures) ,而不用靠括号的位置来表达捕获到的东西 。Perl 5.10 还支持嵌套匹配,使得我们现在可以使用许多有效的匹配结构,尤其是在句法解析时。尽管添加了新的特性,正则表达引擎在很多方面做了精心调整并且提高了速度。

Other improvements include state variables that allow variables to persist between calls to subroutines; user defined pragmata that allow users to write modules to influence the way Perl behaves; a defined-or operator ; field hashes for inside-out objects and better error messages.

其他的改进包括可在函数内持续的状态变量(state variable) ,使用户可以自己调整 Perl 运行方式的用户自定义 pragmata ,一个 "定义或" 的操作符 ,为翻转对象(inside-out objects)提供的符号哈希表(field hashes) ,以及改进的错误信息。

Interpreter improvements
It's not just language changes. The Perl interpreter itself is faster with a smaller memory footprint, and has several UTF-8 and threading improvements. The Perl installation is now relocatable, a blessing for systems administrators and operating system packagers. The source code is more portable, and of course many small bugs have been fixed along the way. It all adds up to the best Perl yet.

For a list of all changes in Perl 5.10, see Perl 5.10's perldelta document included with the source distribution. For a gentler introduction of just the high points, the slides for Ricardo Signes' Perl 5.10 For People Who Aren't Totally Insane talk are well worth reading.

解释器的改进
并非只有程序语言的改进,Perl 解释器本身已变得更快,更少内存占用(memory footprint) ,还有了一些 UTF-8 及线程方面的改进。Perl 的安装方式变成了可移动的,这对系统管理员以及操作系统集成者来说实在是好消息。源代码现在变得更易移植,很多小 bug 也被顺手改正了。所有这一切都造就了目前为止最棒的Perl.

想要了解关于5.10所有的改动,请看 Perl 5.10 源代码版本中自带的perldelta 文档。(link: http://search.cpan.org/dist/perl-5.10.0/pod /perl5100delta.pod) 简易的介绍请看 Ricardo Signes' 的讲义 Perl 5.10 For People Who Aren't Totally Insane (link: http://www.slideshare.net/rjbs/perl-510-for-people-who-arent-totally-insane) 值得一读。

Don't think that the Perl Porters are resting on their laurels. As Rafael Garcia-Suarez, the release manager for Perl 5.10, said: "I would like to thank every one of the Perl Porters for their efforts. I hope we'll all be proud of what Perl is becoming, and ready to get back to the keyboard for 5.12."

不要以为 Perl Porters 们在荣耀之下就止步不前了,正如Perl 5.10 的版本管理员 Rafeal Garcia-suarez 所说:"我想感谢所有 Perl Porters 为此付出的努力。我希望我们能为 Perl 的今天感到自豪,并准备好回到键盘边为 Perl 5.12 继续工作。"

Where to get Perl
Perl is a standard feature in almost every operating system today except Windows. Users who don't want to wait for their operating system vendor to release a package can dig into Perl 5.10 by downloading it from CPAN, the Comprehensive Perl Archive Network, at http://search.cpan.org/dist/perl/[/url], or from the Perl home page at www.perl.org.

Windows users can also take advantage of the power of Perl by compiling a source distribution from CPAN, or downloading one of two easily installed binary distributions. Strawberry Perl is a community-built binary distribution for Windows, and ActiveState 's distribution is free but commercially-maintained. ActiveState's distribution is available now, and Strawberry Perl's is imminent.

如何获取 Perl
除 Windows 外, Perl 几乎是所有操作系统的标准配置。不想慢慢等待系统升级包的用户可以从 CPAN (the Comprehensive Perl Archive Network )自行下载 Perl 5.10 。地址是 http://search.cpan.org/dist/perl/ ,或者从 Perl 的主页 www.perl.org 下载。

Windows 用户可以编译从 CPAN 获取的源代码来取得 Perl,或者也可以下载两个易于安装的已编译版本中的一个。 Strawberry Perl (link: http://strawberryperl.com/) 是社区为 Windows 编译的发行版本,而 ActiveState (link: http://activestate.com/) 的版本由商业公司维护但是同样免费。ActiveState 版本已经可以获取,Stawberry Perl 也即将完成。

Editor's notes
For questions, contact Perl Foundation Public Relations at pr@perlfoundation.org.

Perl: perl.org Perl is a dynamic programming language created by Larry Wall and first released in 1987. Perl borrows features from a variety of other languages including C, shell scripting (sh), AWK, sed and Lisp. It is distributed with practically every version of Unix available and runs on a huge number of platforms, as diverse as Windows, Mac OS X, Solaris, z/OS, os400, QNX and Symbian.

Rafael Garcia-Suarez email: rgarciasuarez@gmail.com Rafael Garcia-Suarez is a French software engineer who lives in Paris, France, and who is currently employed by Booking.com. He has been a contributor to Perl for many years and has stewarded the birth of Perl 5.10 for the last few.

The Perl Foundation perlfoundation.org The Perl Foundation is dedicated to the advancement of the Perl programming language through open discussion, collaboration, design, and code. It is a non-profit, 501(c)(3) organization incorporated in Holland, Michigan, USA in 2000.

编者注
问题请联系 Perl 基金会公共关系部 pr@perlfoundation.org

Perl: perl.org Perl 是 Larry Wall 创造的一门动态程序语言,首次发布于1987 年。Perl 借用了多种语言如 C ,shell(sh), AWK, sed 以及 Lisp 的特性。Perl 已经成为几乎所有 Unix 系统的标准配置之一,并可以在许多的操作系统上运行,包括 Windows,Mac OS X,Solaris,z/OS,os400,QNX 以及 Symbian.

Rafael Garcia-Suarez email: rgarciasuarez@gmail.com

Rafael Garcia-Suarez 是一名生活在巴黎的法国软件工程师,目前是 Booking.com 的一名雇员。多年来他一直是 Perl 的开发者之一,并在最近几年担任着 Perl 5.10 的管理者。

The Perl Foundation perlfoundation.org

Perl 基金会一直致力于 Perl 程序语言的各方面发展。它是一家成立于 2000 年的非营利性组织,位于美国密歇根州 Holland。

该文章最后由 阿炯 于 2012-06-11 09:29:16 更新,目前是第 2 版。