2015年12月5日星期六

[PerlChina] PerlChina Advent Calendar 2015 Day 6

一年一度的12月又到了。前几天看到 Achilles Xu 在github 上发起 https://github.com/PerlChina/advent-2015。我就打算写写过去一年里的收获。今天终于能静下来写一点。

希望大家多参与,如果没时间写,可以提建议 https://github.com/PerlChina/advent-2015/issues, 说不定有人正好想写,但是苦于找不到下手的地方。

https://github.com/PerlChina/advent-2015/blob/master/advent/1206_new_n_flag_in_perl_5_22.md

/n flag in Perl 5.22

Perl 5.22 perldelta 有不少新的改进, 不过,貌似,多数我用不到,所有不太关心,除了正则式新增的  /n  flag。

比如,经常碰到类似的情况,

"hello" =~ /(?:hi|hello)/;  

多数情况下,我的目的就是匹配其中一个,而不是记住哪个匹配了,要是能直接写成

"hello" =~ /(hi|hello)/;  

多好,增加可读性,又方便。Perl 5.22 新增的 /n flag,就是为这种需求而生的。

在Perl 5.22 中

 "hello" =~ /(?:hi|hello)/;  <=> "hello" =~ /(hi|hello)/n;  

/n flag in Perl 5.22







--
您收到此邮件是因为您订阅了Google网上论坛上的"PerlChina Mongers 讨论组"群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com
要发帖到此群组,请发送电子邮件至perlchina@googlegroups.com
访问此群组:http://groups.google.com/group/perlchina
要查看更多选项,请访问https://groups.google.com/d/optout