我正在维护一些通过串行无线电读取值的代码,并将它们解压缩到Perl数据结构中:
# Don't yell at me, I didn't write this
if ($command_string =~
/^.(.)(.).(..)(.)(..)(.)(....)(....)(....)(....)
(..)(..)(.)(.)(.)(.)(..)(..)(..)(..)(..)(..)(.)(.).......
(.)........(.)(.).*/sx) {
$config->{sequence} = hex(unpack('H2', $1));
$config->{radio_id} = hex(unpack('H2', $2));
...
$config->{radio_type} = hex(unpack('H2', $26));
$config->{radio_channel} = hex(unpack('H2', $27));
}
这个笨重的捕获正则表达式让我想知道:Perl中编号捕获变量的上限是什么?它是否一直到$MAXINT
?
答案 0 :(得分:16)
此脚本至少可以使用$N=5000000
。之后,内存不足。
$N = $ARGV[0] || 5000;
$q = '(.)' x $N;
$regex = qr/$q/;
("x" x $N) =~ $regex;
print eval "\$$N";