I'm maintaining some code that reads values over a serial radio and unpacks them into Perl data structures:
# 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));
}
This unwieldy capturing regex made me wonder: what's the upper bound on numbered capture variables in Perl? Does it go all the way up to $MAXINT
?
This script works up to at least $N=5000000
. After that, it runs out of memory.
$N = $ARGV[0] || 5000;
$q = '(.)' x $N;
$regex = qr/$q/;
("x" x $N) =~ $regex;
print eval "\$$N";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With