我正在维护一些代码,通过串行收音机读取值并将其解压缩到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吗?
此脚本的工作速度至少为$N = 5000000.之后,内存不足.
$N = $ARGV[0] || 5000;
$q = '(.)' x $N;
$regex = qr/$q/;
("x" x $N) =~ $regex;
print eval "\$$N";