New here?I want to ask a question of the Perl Monks. Where do I start?

Notices:

hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.

If you're new here, please read PerlMonks FAQ
and Create a new user!

Quests
poll ideas quest 2026
Starts at: Jan 01, 2026 at 00:00
Ends at: Dec 31, 2026 at 23:59
Current Status: Active
0 replies by pollsters
    First, read How do I create a Poll?. Then suggest your poll here. Complete ideas are more likely to be used.

    Note that links may be used in choices but not in the title.

Perl News
Linuxlinks on Perl Static Site Generators
on Feb 20, 2026 at 05:14
0 replies by mldvx4
Perl mentioned at The New Stack
on Feb 13, 2026 at 06:02
3 replies by mldvx4

    The New Stack has mentioned Perl in the context of TIOBE:

    On the scripting side, Perl has also returned to prominence. Once the undisputed leader in scripting, Perl declined after years of internal fragmentation and competition from newer languages, writes Paul Jansen, CEO of TIOBE in the post. “Recently, however, it has staged a comeback, reclaiming a position in the TIOBE top 10 since January 2018,” he writes.

    Perl is actually number 11 on the index right now. It was ranked 30th at the same time last year.

    “It’s hard to judge a programming language’s popularity based on some of the indexes,” Andrew Cornwall, an analyst at Forrester Research, tells The New Stack.

    Statistical language R is making a comeback against Python.

    As we know these rankings are quite arbitrary and the methodology is more than flawed due the selection of repositories surveyed and the ones which get ignored. However, MSFT's long-runnning smear campaign against Perl is losing steam.

Supplications
Reusing a complex regexp in multiple spots, escaping the regexp
3 direct replies — Read more / Contribute
by ecm
on Apr 12, 2026 at 15:27

    I have a fairly complex regexp, consisting of 9 match groups one of which has to match. I'm using copies of the exact same regexp in 4 different spots. All of them should match the same text. However, in one spot I want to access the match parameters as in $1 to $9, while in the other spots only one parameter ($3) and $`, $&, and $' are used.

    How do I abstract a regexp so I only need to define and update it in one spot, but still be able to access the capture match groups anyway?

    I tried storing the regexp pattern in a string variable then use that variable in the search, but I don't know how to correctly set the variable to a multi-line string (using a here document?) and use that for the pattern. Below is a dump of the working code, then the failing code and the error messages:

    Working:
    while (not $second and $linking =~ /(\bINT\s?[0-9A-Fa-f]{2}[Hh]? (?:\/(?:E?[ABCD][XHL]|E?[SD]I|E?[SB]P|[DESC]S)=[0-9A-F +a-f]{2,}[Hh]?)+ (?:\"[^"]+\")? ) |(\bINT\s?[0-9A-Fa-f]{2}[Hh]? (?:\"[^"]+\")? ) |(\b(?:E?A[XHL])=[0-9A-Fa-f]{2,}[Hh]? (?:\/(?:E?[ABCD][XHL]|E?[SD]I|E?[SB]P|[DESC]S)=[0-9A-F +a-f]{2,}[Hh]?)* (?:\"[^"]+\")? ) |(\#[0-9A-Z][0-9]{4}\b) |(\bMEM\s?[0-9A-Fa-fXx]{1,4}[Hh]?:[0-9A-Fa-fXx]{1,4}[Hh] +? (?:\"[^"]+\")? ) |(\bMEM\s?[0-9A-Fa-fXx]{1,8}[Hh]? (?:\"[^"]+\")? ) |(\@[0-9A-Fa-fXx]{1,4}[Hh]?:[0-9A-Fa-fXx]{1,4}[Hh]? (?:\"[^"]+\")? ) |(\bPORT\s?[0-9A-Fa-fXx]{1,4}[Hh]?-[0-9A-Fa-fXx]{1,4}[Hh +]? (?:\"[^"]+\")? ) |(\bPORT\s?[0-9A-Fa-fXx]{1,4}[Hh]? (?:\"[^"]+\")? ) /x) { my $intplus = $1; my $intonly = $2; my $regonly = $3; if (defined $regonly and not defined $int) { if (defined $link) { print_or_errorline("Entered reg only link without im +plicit INT"); return; } $maskhighlight .= " " x (length($`) + length($&)); $linking = $'; next; } my $table = $4; my $mem_16_16 = $5; my $mem_32 = $6; my $call = $7; my $portrange = $8; my $portsingle = $9; $maskhighlight .= " " x length $`;
    Failing:
    my $linkpattern = <<PATTERNEND; (\bINT\s?[0-9A-Fa-f]{2}[Hh]? (?:\/(?:E?[ABCD][XHL]|E?[SD]I|E?[SB]P|[DESC]S)=[0-9A-F +a-f]{2,}[Hh]?)+ (?:\"[^\"]+\")? ) |(\bINT\s?[0-9A-Fa-f]{2}[Hh]? (?:\"[^\"]+\")? ) |(\b(?:E?A[XHL])=[0-9A-Fa-f]{2,}[Hh]? (?:\/(?:E?[ABCD][XHL]|E?[SD]I|E?[SB]P|[DESC]S)=[0-9A-F +a-f]{2,}[Hh]?)* (?:\"[^\"]+\")? ) |(\#[0-9A-Z][0-9]{4}\b) |(\bMEM\s?[0-9A-Fa-fXx]{1,4}[Hh]?:[0-9A-Fa-fXx]{1,4}[Hh] +? (?:\"[^\"]+\")? ) |(\bMEM\s?[0-9A-Fa-fXx]{1,8}[Hh]? (?:\"[^\"]+\")? ) |(\@[0-9A-Fa-fXx]{1,4}[Hh]?:[0-9A-Fa-fXx]{1,4}[Hh]? (?:\"[^\"]+\")? ) |(\bPORT\s?[0-9A-Fa-fXx]{1,4}[Hh]?-[0-9A-Fa-fXx]{1,4}[Hh +]? (?:\"[^\"]+\")? ) |(\bPORT\s?[0-9A-Fa-fXx]{1,4}[Hh]? (?:\"[^\"]+\")? ) PATTERNEND while (not $second and $linking =~ /$linkpattern/x) { my $intplus = $1; my $intonly = $2; my $regonly = $3; if (defined $regonly and not defined $int) { if (defined $link) { print_or_errorline("Entered reg only link without im +plicit INT"); return; } $maskhighlight .= " " x (length($`) + length($&)); $linking = $'; next; } my $table = $4; my $mem_16_16 = $5; my $mem_32 = $6; my $call = $7; my $portrange = $8; my $portsingle = $9; $maskhighlight .= " " x length $`;
    My program uses curses for a TUI, so I redirected stderr to a file to capture perl error messages:
    Unrecognized escape \s passed through at /home/[user]/proj/tractest/in +tlist.pl line 419. Unrecognized escape \s passed through at /home/[user]/proj/tractest/in +tlist.pl line 419. Unrecognized escape \s passed through at /home/[user]/proj/tractest/in +tlist.pl line 419. Unrecognized escape \s passed through at /home/[user]/proj/tractest/in +tlist.pl line 419. Unrecognized escape \s passed through at /home/[user]/proj/tractest/in +tlist.pl line 419. Unrecognized escape \s passed through at /home/[user]/proj/tractest/in +tlist.pl line 419. Unmatched ( in regex; marked by <-- HERE in m/ INTs?[0-9A +-Fa-f]{2}[Hh]? (?:/(?:E?[ABCD][XHL]|E?[SD]I|E?[SB]P|[DESC]S)=[0-9A-Fa +-f]{2,}[Hh]?)+ (?:"[^"]+")? ) |INTs?[0-9A-Fa-f]{2}[Hh]? (?:"[^"]+")? ) |(?:E?A[XHL])=[0-9A-Fa-f]{2,}[Hh]? (?:/(?:E?[ABCD][XHL]|E?[SD]I|E?[SB]P|[DESC]S)=[0-9A-Fa +-f]{2,}[Hh]?)* (?:"[^"]+")? ) |(#[0-9A-Z][0-9]{4) <-- HERE |MEMs?[0-9A-Fa-fXx]{1,4}[Hh]?:[0-9A-Fa-fXx]{1, +4}[Hh]? (?:"[^"]+")? ) |MEMs?[0-9A-Fa-fXx]{1,8}[Hh]? (?:"[^"]+")? ) |(@[0-9A-Fa-fXx]{1,4}[Hh]?:[0-9A-Fa-fXx]{1,4}[Hh]? (?:"[^"]+")? ) |PORTs?[0-9A-Fa-fXx]{1,4}[Hh]?-[0-9A-Fa-fXx]{1,4}[Hh]? (?:"[^"]+")? ) |PORTs?[0-9A-Fa-fXx]{1,4}[Hh]? (?:"[^"]+")? ) / at /home/[user]/proj/tractest/intlist.pl line 447, <$array_lstff[... +]> line 197305.
NFS File Locking
5 direct replies — Read more / Contribute
by jbw8387
on Apr 08, 2026 at 09:02

    I have an NFS file system mounted on many machines. I am attempting to use file locking to get exclusive access by one system to a file. The critical code section shown here:

    # loop through file names looking for one we can lock open ( my $file_handle, '+<', $file_name ) or next; if ( !flock( $file_handle, LOCK_EX | LOCK_NB ) ) { close( $file_handle ); next; } # do some work here based on the file contents unlink $file_name; close( $file_handle );

    This almost always works, but occasionally there is a failure where two machines get a lock on the same file. It appears there is a race between unlinking (deleting) the file and releasing the lock. It seems like there is a small window where the lock is actually released before the file is deleted allowing another machine to lock and read the file before it is deleted.

    I am wondering if this is a known problem and if there is a preferred way to work around this.