gpt4 book ai didi

regex - 超过复杂正则子表达式递归限制 (32766)

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:08:06 25 4
gpt4 key购买 nike

我有一个执行 pgrep 的 perl 脚本,如下所示:

use warnings;

my @instance = `pgrep -fl varnish`;
foreach my $line (@instance) {
my $ip;
my $port;
my $pid;
my $pidfile;
my $fileconfiguration;
my $bakendhost;
my $bakendport;
my $sharememory;
my $user;

chomp $line;
if ($line =~ m/-T\s+([0-9]+.*)+:(\d+)\s+/) {
$ip = $1;
$port = $2;
}
}

但是当启动脚本时出现以下错误/警告:

Complex regular subexpression recursion limit (32766) exceeded at /home/k.sewnundun/test.pl line 16.

Complex regular subexpression recursion limit (32766) exceeded at /home/k.sewnundun/test.pl line 16.

调试如下:

Loading DB routines from perl5db.pl version 1.32
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(/home/k.sewnundun/test.pl:3):
3: my @instance = `pgrep -fl varnish`;
DB<1> n
main::(/home/k.sewnundun/test.pl:4):
4: foreach my $line (@instance) {
DB<1> n
main::(/home/k.sewnundun/test.pl:5):
5: my $ip;
DB<1> print $line
3066 /opt/rh/varnish4/root/usr/sbin/varnishd -P /var/run-daemon/varnishd-toto4.pid -a 0.0.0.0:8080 -f /etc/varnish/etc/toto4/toto4-current.vcl -u varnish4-toto4 -g varnish4-toto4 -l 80M -T 0.0.0.0:38080 -p thread_pool_min=50 -p thread_pool_max=1000 -p thread_pool_timeout=120 -p vcl_dir=/etc/varnish/etc/toto4 -n /home/varnish/toto4/working -s malloc, -S /etc/varnish/etc/toto4/toto4.secret

DB<2> n
main::(/home/k.sewnundun/test.pl:6):
6: my $port;
DB<2> n
main::(/home/k.sewnundun/test.pl:7):
7: my $pid;
DB<2> n
main::(/home/k.sewnundun/test.pl:8):
8: my $pidfile;
DB<2> n
main::(/home/k.sewnundun/test.pl:9):
9: my $fileconfiguration;
DB<2> n
main::(/home/k.sewnundun/test.pl:10):
10: my $bakendhost;
DB<2> n
main::(/home/k.sewnundun/test.pl:11):
11: my $bakendport;
DB<2> n
main::(/home/k.sewnundun/test.pl:12):
12: my $sharememory;
DB<2> n
main::(/home/k.sewnundun/test.pl:13):
13: my $user;
DB<2> n
main::(/home/k.sewnundun/test.pl:15):
15: chomp $line;
DB<2> n
main::(/home/k.sewnundun/test.pl:16):
16: if ($line =~ m/-T\s+([0-9]+.*)+:(\d+)\s+/) {
DB<2> n
main::(/home/k.sewnundun/test.pl:17):
17: $ip = $1;
DB<2> n
main::(/home/k.sewnundun/test.pl:18):
18: $port = $2;
DB<2> n
main::(/home/k.sewnundun/test.pl:5):
5: my $ip;
DB<2> print $line
3078 /opt/rh/varnish4/root/usr/sbin/varnishd -P /var/run-daemon/varnishd-toto4.pid -a 0.0.0.0:8080 -f /etc/varnish/etc/toto4/toto4-current.vcl -u varnish4-toto4 -g varnish4-toto4 -l 80M -T 0.0.0.0:38080 -p thread_pool_min=50 -p thread_pool_max=1000 -p thread_pool_timeout=120 -p vcl_dir=/etc/varnish/etc/toto4 -n /home/varnish/toto4/working -s malloc, -S /etc/varnish/etc/toto4/toto4.secret

DB<3> n
main::(/home/k.sewnundun/test.pl:6):
6: my $port;
DB<3> n
main::(/home/k.sewnundun/test.pl:7):
7: my $pid;
DB<3> n
main::(/home/k.sewnundun/test.pl:8):
8: my $pidfile;
DB<3> n
main::(/home/k.sewnundun/test.pl:9):
9: my $fileconfiguration;
DB<3> n
main::(/home/k.sewnundun/test.pl:10):
10: my $bakendhost;
DB<3> n
main::(/home/k.sewnundun/test.pl:11):
11: my $bakendport;
DB<3> n
main::(/home/k.sewnundun/test.pl:12):
12: my $sharememory;
DB<3> n
main::(/home/k.sewnundun/test.pl:13):
13: my $user;
DB<3> n
main::(/home/k.sewnundun/test.pl:15):
15: chomp $line;
DB<3> n
main::(/home/k.sewnundun/test.pl:16):
16: if ($line =~ m/-T\s+([0-9]+.*)+:(\d+)\s+/) {
DB<3> n
main::(/home/k.sewnundun/test.pl:17):
17: $ip = $1;
DB<3> n
main::(/home/k.sewnundun/test.pl:18):
18: $port = $2;
DB<3> n
main::(/home/k.sewnundun/test.pl:5):
5: my $ip;
DB<3> print $line
3200 /opt/rh/varnish4/root/usr/bin/varnishncsa -a -n toto4 -w /home/logs/varnish/toto4/access.log -D -P /var/run-daemon/varnishncsa-toto4.pid -F %{X-Forwarded-For}i %h %l %u %t "%r" %s %b "%{Referer}i" "%{User-agent}i"

DB<4> n
main::(/home/k.sewnundun/test.pl:6):
6: my $port;
DB<4> n
main::(/home/k.sewnundun/test.pl:7):
7: my $pid;
DB<4> n
main::(/home/k.sewnundun/test.pl:8):
8: my $pidfile;
DB<4> n
main::(/home/k.sewnundun/test.pl:9):
9: my $fileconfiguration;
DB<4> n
main::(/home/k.sewnundun/test.pl:10):
10: my $bakendhost;
DB<4> n
main::(/home/k.sewnundun/test.pl:11):
11: my $bakendport;
DB<4> n
main::(/home/k.sewnundun/test.pl:12):
12: my $sharememory;
DB<4> n
main::(/home/k.sewnundun/test.pl:13):
13: my $user;
DB<4> n
main::(/home/k.sewnundun/test.pl:15):
15: chomp $line;
DB<4> n
main::(/home/k.sewnundun/test.pl:16):
16: if ($line =~ m/-T\s+([0-9]+.*)+:(\d+)\s+/) {
DB<4> n
main::(/home/k.sewnundun/test.pl:5):
5: my $ip;
DB<4> print $line
9803 varnishd -P /var/run-daemon/varnishd-varnish.pid -a 0.0.0.0:80 -f /etc/varnish/varnish.com/varnish.vcl -u varnish-varnish -l 80M -T 127.0.0.1:33080 -w 200,500,120 -n /home/varnish/varnish/working -s malloc,1G -p user varnish-varnish -p acceptor_sleep_decay 0.9 -p acceptor_sleep_incr 0.001 -p acceptor_sleep_max 0.05 -p auto_restart on -p ban_lurker_sleep 0.0 -p between_bytes_timeout 60.0 -p cli_buffer 8192 -p cli_timeout 5 -p clock_skew 10 -p connect_timeout 0.4 -p critbit_cooloff 180.0 -p default_grace 10 -p default_ttl 120 -p diag_bitmap 0x0 -p esi_syntax 0 -p expiry_sleep 1.0 -p fetch_chunksize 128 -p first_byte_timeout 60.0 -p group varnish-varnish -p http_range_support off -p listen_depth 1024 -p log_hashstring off -p log_local_address off -p lru_interval 2 -p max_esi_depth 5 -p max_restarts 4 -p ping_interval 3 -p pipe_timeout 60 -p prefer_ipv6 off -p queue_max 100 -p rush_exponent 3 -p saintmode_threshold 10 -p send_timeout 600 -p sess_timeout 5 -p sess_workspace 16384 -p session_linger 50 -p session_max 10000 -p shm_reclen 255 -p shm_workspace 8192 -p syslog_cli_traffic on -p vcl_trace off -p vcl_dir -p waiter default

DB<5> n
main::(/home/k.sewnundun/test.pl:6):
6: my $port;
DB<5> n
main::(/home/k.sewnundun/test.pl:7):
7: my $pid;
DB<5> n
main::(/home/k.sewnundun/test.pl:8):
8: my $pidfile;
DB<5> n

main::(/home/k.sewnundun/test.pl:9):
9: my $fileconfiguration;
DB<5> main::(/home/k.sewnundun/test.pl:10):
10: my $bakendhost;
DB<5> n
main::(/home/k.sewnundun/test.pl:11):
11: my $bakendport;
DB<5> n
main::(/home/k.sewnundun/test.pl:12):
12: my $sharememory;
DB<5> n
main::(/home/k.sewnundun/test.pl:13):
13: my $user;
DB<5> n
main::(/home/k.sewnundun/test.pl:15):
15: chomp $line;
DB<5> n
main::(/home/k.sewnundun/test.pl:16):
16: if ($line =~ m/-T\s+([0-9]+.*)+:(\d+)\s+/) {
DB<5> n
Complex regular subexpression recursion limit (32766) exceeded at /home/k.sewnundun/test.pl line 16.
at /home/k.sewnundun/test.pl line 16
main::(/home/k.sewnundun/test.pl:17):
17: $ip = $1;
DB<5> q

可能是什么问题?谢谢

最佳答案

这是一个好兆头,表明您的正则表达式有误。正如评论中所指出的那样 - 你嵌套量词可能会导致问题,尤其是当匹配重叠时......(例如 . 也匹配 [0-9]) .有几个人在评论中提到了这一点——特别是像 ([0-9]+.*)+ 这样的东西——如果没有找到匹配项,你最终不得不回溯各种不同的组合字母/数字以确定是否存在匹配项。

如果您尝试类似 use re 'debug' 的操作并注意您的正则表达式如何开始运行大量的步骤来处理,您可能会看到它在起作用。

但是当您停止解析 pgrep 的输出,而是使用类似 Proc::ProcessTable 的东西时,这是一个有争议的问题:

#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
use Proc::ProcessTable;

my $ps = Proc::ProcessTable -> new;

foreach my $proc ( grep { $_ -> {cmndline} =~ m/varnish/ } @{$ps->table} ) {
my %opts = $proc -> {cmndline} =~ m/\-(\w) (\S+)/g;
print Dumper $proc;
print Dumper \%opts;

my ( $IP, $port ) = split ( ':', $opts{'T'});
}

关于regex - 超过复杂正则子表达式递归限制 (32766),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34200336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com