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.
Looks like the consensus on how to approach this would be to "split, sort, join" to generate keys for finding pair pals. Further, as smarter guys explained, using modulo arithmetic voodoo, a lot of unfriendly numbers (which can't have any pals anyway) should simply be skipped; and, of those that remain, it's pointless to ask some of the witnesses about, i.e skip these witnesses, too. So, my subroutine to solve the problem is:
However, even though some solutions mention "speed", I haven't seen optimizations which follow. First, if using CPAN modules is OK (and why not), almost exactly twice as fast is to sort in-place instead:
I have turned perlcritic --stern towards several scripts I have and encountered a question. The manual page for File::Path contains the following excerpt:
Seeking community wisdom on why the ApacheBench utility consistently returns a lot of "Non-2xx responses" ( 502 Bad Gateway ) when running a benchmark test of my helloworld web app using Perl's Net::Async::FastCGI and Nginx as a reverse proxy. The number of concurrent requests is pretty low at 50, but it still return lots of "Non-2xx responses"?? Any insight is greatly appreciated. Please see below for the test code and the ApacheBench command for benchmark test:
1. ApacheBench command: Send 100 requests at concurrency level of 50:
==============================================================================
ab -l -v 2 -n 100 -c 50 "http://localhost:9510/helloworld/"<br/>
...
Concurrency Level: 50
Time taken for tests: 0.015 seconds
Complete requests: 100
Failed requests: 0
Non-2xx responses: 85 #NOTE: all of these are "502 Bad Gateway"
...
I am not thoroughly knowledgeable about the NTFS (my Windows 11 filesystem is NTFS), but it appears there's a portability gotcha in File::Copy::Recursive::Reduced, as illustrated in the console output below:
"C:\berrybrew\instance\5.40.2_64\perl\bin\perl.exe" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib\lib', 'blib\arch')" t/*.t
Unable to symlink C:\Users\somia\AppData\Local\Temp\_VXLTq6lRt\sym to target C:\Users\somia\AppData\Local\Temp\_VXLTq6lRt\old for testing: Operation not permitted at t/001-fcopy.t line 71.
# Looks like your test exited with 1 just after 9.
t/001-fcopy.t ....
Dubious, test returned 1 (wstat 256, 0x100)
Failed 76/85 subtests
(less 1 skipped subtest: 8 okay)
Unable to symlink at t/lib/Helper.pm line 179.
# Looks like your test exited with 1 just after 77.
t/002-dircopy.t ..
Dubious, test returned 1 (wstat 256, 0x100)
Failed 38/115 subtests
(less 1 skipped subtest: 76 okay)
Unable to symlink C:\Users\somia\AppData\Local\Temp\6cvtKrEDFd\sym to target C:\Users\somia\AppData\Local\Temp\6cvtKrEDFd\old for testing: Operation not permitted at t/003-rcopy.t line 78.
# Looks like your test exited with 1 just after 9.
t/003-rcopy.t ....
Dubious, test returned 1 (wstat 256, 0x100)
Failed 179/188 subtests
(less 1 skipped subtest: 8 okay)
As always, I will greatly appreciate any knowledge and insights. Thanks, good monks.
Dec 02, 2025 at 03:05 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)
Hi, I am currently using Filesys::SmbClient to access a text file but when using tcpdump I notice that the path etc are not encrypted. How do I force encryption?
I have set the following at: ~/.smb/smb.conf and /etc/samba/smb.conf
When I use /usr/bin/smbclient the stuff seems to be encrypted. However safely passing passwords to smbclient appears to be trickier and more troublesome.
However, when using DBI, the command errors out with this error info: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM articles_table' at line 1
If I put the articles table into double quotation marks, the error message is slightly different: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"articles_table"' at line 1
As said, the errors occur ONLY from DBI!
To make sure that there is no permissions problem etc, I even let DBI log on the MySQL server as root.
Any idea how to proceed when when things just look and work fine on the server console, but throw syntax errors when using DBI?
Edit:
Basically the code that fails is this:
my $my_articletable = 'articles_table';
my $p_db_art_id = 'db_art_id';
my $sqlcmd = "SELECT MAX($p_db_art_id) FROM $my_articletable;";
logit("SQLCMD: '$sqlcmd'");
my $sth = $p_dbh->prepare($sqlcmd);
$sth->execute();
As said, copypasting the resulting SQL command "SELECT MAX(db_art_id) FROM articles_table;" from the logfile into the MySQL monitor console does not give any hint what could be wrong, it just does what it is supposed to do.
I am participating in a coding-contest, where you have to steer a bot through an arena and collect gems.
(hidden gems (german only)). I am one of only two contestants using perl.
As part of the rules the bot must behave deterministic - two runs in the same arena need to result in the same result.
For random numbers this is ensured by setting a fixed seed in srand().
The challenge comes with hashes, which by design are unordered. Here I ensure determinism using sort on the keys.
But now I want to access the hash based on the order of a field inside:
- and the values are not unique. This line resulted in non-determinism (and therefore my bot was excluded from tonights competition).
Is there a way to force perl to access a hash in a deterministic way? Similar to srand()? Or what is the preferred way to enforce it?
I could try something like
I have a GUI based application written by me in Perl, using Perl-Tk for the GUI. This application runs well on Linux, Windows and macOS (on macOS it requires an installed X11 server for the GUI).
In order to distribute this application to Windows users I packaged it up into an exe file using ParPacker and this works really well, no complaints from the users.
I tried using ParPacker on macOS but ran into problems with X11 and other libraries not being found as their location varies depending on the X11 server installed and depending on which packaging system is being used, there is XQuartz and there are X11 servers in Homebrew and Macports and there are even various distributions of Perl and related modules (the limited Perl included in macOS and the Perl packages from Homebrew and Macports), each using different paths and apparently also different library versions.
It seemed very much a mess to me and even after days of trying I wasn't able to find a satisfactory solution.
So has anybody successfully packaged up a Perl-Tk application for macOS and if yes how exactly did you do it, using ParPacker or some other method?
Any hints would be very helpful. TIA.