如何限制Perl拆分中返回的项目数?

Nan*_* HE 1 perl parsing split

当我解析包含数千行的复杂文件时,我遇到了问题.

我已经像今天一样实现了我的Perl脚本.

 my ($head, $tail) = split /=/, $line;
Run Code Online (Sandbox Code Playgroud)

我的几乎所有源文件$line样式如下:

constant normalLines = <type value>     /*  hello world  */
Run Code Online (Sandbox Code Playgroud)

我可以得到输出 $tail = /* hello world */

今天我在解析这样的行时发现了一个错误(行中有两个=)

constant specialLine = <type value>     /*  hello = world  */
Run Code Online (Sandbox Code Playgroud)

但现在输出是 $tail = /* hello

如何split()在上面的代码中修复仍然使用的bug ?我仍然想要输出$tail = /* hello = world */

Thi*_*ilo 7

您可以指定限制参数来告诉你想在最有多少部分:

# split /PATTERN/,EXPR,LIMIT

my ($head, $tail) = split /=/, $line, 2;
Run Code Online (Sandbox Code Playgroud)