PerlChina Advent Calendar 2015 Day 6

25 views
Skip to first unread message

Hao Wu

unread,
Dec 5, 2015, 7:10:18 PM12/5/15
to perl...@googlegroups.com
一年一度的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







Reply all
Reply to author
Forward
0 new messages