If
you have a question on how to do something in Perl, or
you need a Perl solution to an actual real-life problem, or
you're unsure why something you've tried just isn't working...
then this section is the place to ask.
However, you might consider asking in the chatterbox first (if you're a
registered user). The response time tends to be quicker, and if it turns
out that the problem/solutions are too much for the cb to handle, the
kind monks will be sure to direct you here.
I tried installing Test2::Harness and a couple tests failed. I am not totally understanding the output
and if someone knowledgeable could interpret this for me I'd be grateful.
Running make test for EXODIST/Test2-Harness-1.000170.tar.gz
PERL_DL_NONLAZY=1 "/usr/bin/perl.exe" "-Iblib/lib" "-Iblib/arch" test.pl
FAIL job 46 +~find_in_updir
PASS job 46 + Found file in expected spot
FAIL job 46 + Found file in expected spot
DEBUG job 46 | t/unit/App/Yath/Util.t line 133
( DIAG ) job 46 | +---------+----+-----------------------------------------------------------+
( DIAG ) job 46 | | GOT | OP | CHECK |
( DIAG ) job 46 | +---------+----+-----------------------------------------------------------+
( DIAG ) job 46 | | <UNDEF> | =~ | (?^:\/cygdrive\/c\/Users\/somia\/AppData\/Local\/Temp\/ya |
( DIAG ) job 46 | | | | th\-149000\-j3p7oZ\/tmp\/FJbCQG\/17DQP5yPmV\/thefile$) |
( DIAG ) job 46 | +---------+----+-----------------------------------------------------------+
PLAN job 46 | Expected assertions: 2
job 46 ^
( DIAG ) job 46 Failed test 'find_in_updir'
( DIAG ) job 46 at t/unit/App/Yath/Util.t line 134.
-------------------------------------------------------------------------------------------
FAIL job 57 + /cygdrive/c/Users/somia/AppData/Local/Temp has correct permissions
DEBUG job 57 t2/tmp_perms.t line 36
The following jobs failed at least once:
+--------------------+-----------+--------------------+--------------------+
| Job ID | Times Run | Test File | Succeeded Eventual |
| | | | ly? |
+--------------------+-----------+--------------------+--------------------+
| | | | |
| 796D54CF-8067-1014 | 2 | t/unit/App/Yath/Ut | NO |
| -B37C-A366FD41E411 | | il.t | |
| | | | |
| 7973C25C-8067-1014 | 2 | t2/tmp_perms.t | NO |
| -B37C-A366FD41E411 | | | |
+--------------------+-----------+--------------------+--------------------+
The following jobs failed:
+---------------------------------+------------------------+---------------+
| Job ID | Test File | Subtests |
+---------------------------------+------------------------+---------------+
| 796D54CF-8067-1014-B37C-A366FD4 | t/unit/App/Yath/Util.t | find_in_updir |
| 1E411 | | |
| | | |
| 7973C25C-8067-1014-B37C-A366FD4 | t2/tmp_perms.t | |
| 1E411 | | |
+---------------------------------+------------------------+---------------+
Yath Result Summary
-------------------------------------------------------------------------------------------
Fail Count: 2
File Count: 91
Assertion Count: 1996
Wall Time: 632.81 seconds
CPU Time: 1960.39 seconds (usr: 3.67s | sys: 1.70s | cusr: 459.45s | csys: 1495.57s)
CPU Usage: 309%
--> Result: FAILED <--
yath exited with 256 yath exited with 256
not ok 1 - Passed tests when run by yath (allow fork)
not ok 2 - Passed tests when run by yath (no fork)
-------------------------------------------------------------------------------------------
My Perl and System characteristics:
cygwin_nt-10.0-26200 - 3.7.0
AMD Ryzen 5 4600H with Radeon Graphics (AuthenticAMD 3000MHz) x86_64
Perl (/usr/bin/perl:
This is perl 5, version 40, subversion 3 (v5.40.3) built for x86_64-cygwin-threads-multi
Thanks, all.
– Soren
Apr 15, 2026 at 18:38 UTC
A just machine to make big decisions
Programmed by fellows (and gals) with compassion and vision
We'll be clean when their work is done
We'll be eternally free yes, and eternally young Donald Fagen —> I.G.Y. (Slightly modified for inclusiveness)
% perl -MExtUtils::Installed -le 'print for ExtUtils::Installed->new->
+files("Catalyst")'
Catalyst is not installed at -e line 1.
% perl -MModule::Metadata -le 'print Module::Metadata->new_from_module
+("Catalyst")->{filename}'
/perl5/perlbrew/perls/perl-5.42.0/lib/site_perl/5.42.0/Catalyst.pm
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 $`;
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.
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.
Been a lurker since ~2k and an active member since ~2k9. Threw a question to "AI" the other day to write a script to safely allow me to update an iptables chain that I need to implement remotely. The result is below. My question for the monks isn't a question. It's a request from an old timer to see if there are any newcomers who can rewrite this script in Perl, properly.
#!/bin/sh
# apply-new-iptables.sh
OLD=/root/iptables-old.rules
NEW=/root/iptables-new.rules
# backup current
iptables-save > "$OLD"
# apply new rules
iptables-restore < "$NEW"
# start rollback timer: restore OLD after 60s if not canceled
( sleep 60 && iptables-restore < "$OLD" ) &
ROLLBACK_PID=$!
echo $ROLLBACK_PID > /tmp/iptables-rollback.pid
echo "New rules applied. To keep them, run: kill $(cat /tmp/iptables-r
+ollback.pid) && rm /tmp/iptables-rollback.pid"
I need to get the list of network interface names and the network addresses to which they are bound. Unfortunately there's no standard method for this, and the two recommended CPAN modules (IO::Interface and Net::Interface) are buggy and unmaintained. So I am currently parsing the output of `ifconfig -a` or `ip addr show`. This works for my test machines, but I'm planning on distributing the script, so need to maximize portability among unixes.
Using SIOCGIFCONF looks like an interesting alternative, but the only perl example I found is very non-portable: Re: How do I get the local internet IP address?. sys/ioctl.ph isn't present in any of my perlbrewed perls, and even after running h2ph, it fails with "unsupported architecture" for macOS. But I did confirm with the following C program that SIOCGIFCONF is relatively portable when implemented right: https://gist.github.com/OrangeTide/909204.
I am reading a .docx file in Russian. The code $text =~ s/^Испытательная(.*?)/\1/ug; is supposed to process a line by removing part of the text. If the text is written in English, everything is detected and trimmed correctly, but I cannot get it to work with Russian text. In the console, instead of Russian text, I see garbled characters. I've been dancing around encodings — utf8, utf16, cp1251, cp1252 — but none of them give the desired result. Apparently, I am doing something wrong.
Important! When the text is written to a text file from the Word document, it displays correctly.
I would appreciate your help. Thank you.
#!/usr/bin/perl
use Win32::OLE;
use Win32::OLE::Enum;
use utf8;
use strict;
my $text;
my $paragraph;
my $document = Win32::OLE -> GetObject($ARGV[1]);
open (FH,">$ARGV[0]") || die "Can't open file: $!\n";
my $paragraphs = $document->Paragraphs();
my $enumerate = new Win32::OLE::Enum($paragraphs);
while(defined($paragraph = $enumerate->Next()))
{
$text = $paragraph->{Range}->{Text};
$text =~ s/^Испытатk
+7;льная(.*?)/\1/ug;
$text =~ s/[\n\r]//g;
print FH "$text\n";
}
All,
Disclaimer:
This is not a Perl question though I have often found working on memory management problems like this helps improve my Perl. Additionally, I am not a chess player - I have probably played less than a dozen games in my life so I may be way off base here.
First 8 bytes = 64 bit string representing the positions of the white pieces on the board
Next 8 bytes = 64 bit string representing the positions of the black pieces on the board
Next 6 bytes = Sixteen 3 bit strings representing the white pieces (pawn, rook, knight, bishop, king, queen)
Next 1 byte = 1 bit representing black/white's turn, 4 bits representing what type of castling is still possible, 3 bits representing the column the last turn moved the pawn 2 places
That last 3 bits may be hard to understand but in en passant, if your opponent moves 2 places to avoid being attacked by a pawn you already have in position, you have the option to capture that pawn but you must immediately do so on your next turn. These bits serve to either tell you that en passant is possible and which piece is able to be attacked, or if en passant is not possible is set to an invalid column.
There are admittedly a few things that these 23 bytes do not encode:
Previous board configurations leading to the three-fold repetition or five-fold repetition draw rules
Number of previous moves without pawn move or capture for 50/75 move draw rules
Time remaining for each player if time control is employed
While the 3 or 5 board position repetition is beyond the scope of this approach (you would essentially have to serialize every board from every move), you could fairly easily add a byte or two in order to address time and 50/75 move draw rules if you wanted.
An interesting aspect of the approach I have provided is that you can go with either fixed length records (every serialized board is 23 bytes) or with variable length since the number of white and black pieces can be read from the first 16 bytes.
My question to you is - can you see a way to save any more space? This was a thought experiment so I have no practical use but it did keep me up for a long time so I want to make sure I am not missing something sneaky/creative.