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 have an online game with the game server written in Perl 5.32 hosted on Amazon Linux where players connect from their browser using web sockets. In addition to real players connecting, Bot players can also connect which is via a Perl script on the same server where the game server is running. The game works fine but of course you have to consider cases where a user wants to explicitly quit the game, closes their browser (or tab) or refreshes their browser tab. To deal with these I set an alarm for 1 second whenever getting a disconnect. If a player was just refreshing their browser, they will reconnect immediately cancelling the alarm and all is good. If they were explicitly quitting or closed their browser tab, there will be no reconnect and the alarm should go off and the sub will remove them from the game. This all works fine when it's just real players in a game all connected from their browser. However, when there is one or more bots connected and one of the real players disconnects, the alarm is set but NEVER goes off.
The failure occurs the next time the game server has to send a message out to all connected players. Since the alarm didn't go off, that disconnected player didn't get removed from the list. And when time the game server tries to send a message to that player, it pukes due to a syswrite error on the socket that was internally closed.
I have tried using unsafe signals and POSIX signal handler but neither of these work any differently or better.
$conn->on(
disconnect => sub {
my $disconnectPlayer = $self->{players}->getPlayerWithSocket(
+$conn );
$SIG{ALRM} = sub { $self->playerDisconnected() };
$self->{playerDisconnected} = 1;
$self->{disconnectedPlayerSocket} = $conn;
alarm( 1 );
}
);
the code could pass the check, but when I run it, it throws: "mmap failed!!: The handle is invalid at ccc.pl line 29." It seems that the handle I passed from $fh is not correct. My question is what the windows Handle is, and how I get in perl?
Okay, I think, I understand what the BEGIN block does. But I don't understand why this feature was added to Perl. When programming in C or JavaScript or BASIC, I never needed a BEGIN block, so I cannot imagine why would one want to use this or what situation would warrant its use. Why is this important to have in Perl? Was this just a nice feature that was added to make the language more versatile, or does it actually solve a real-life problem? I mean can someone show me a real-life scenario where the BEGIN block is a must have, and you cannot live without it?
I am packaging a new perl distribution ( because https://pault.com/perl.html ) and I am looking for perl users, who might want to give it a try. I need to figure out a lot of stuff with current perl situation, so I tried to subscribe to various perl mailing lists that used to work 20 years ago and they simply do not work now. Somehow. Do you guys and gals know, how can I find the active Perl mailing lists? I only need to find a few people who care about perl as a language and would like to use perl for new challenges. Perl is the only language that makes sense to me last few years and I would keep it going. I have 70% done, planning to turn into 100% next few months.
Is there an elegant way to return out of a module early? I like the style in subs of something like return unless $arg and wanted something similar in packages/modules. I know I can put all the logic in subs and conditionally call the subs, but TMTOWTDI. This seems to work but is ugly: BEGIN { local $SIG{__DIE__}; die if $check }.
I'm writing mod-perl handler scripts to run on Apache 2.4 under Ubuntu 24.04. I'm using mod_authnz_ldap to connect to an Active Directory for authentication and authorization. mod_authnz_ldap relies on mod-ldap and the docs for mod-ldap only discuss it providing LDAP services to other modules.
My handler script needs to make several LDAP queries and I would like to take advantage of mod-ldap's persistent connections and operation cache.
Is this possible? It's very hard to find relevant documentation on the web because of the huge number of search results regarding authentication, authorization, Net::LDAP and, of course, Apache's own Directory Server software. Can anyone point me at relevant material or give me some hints?
I come seeking your wisdom once more. Today, the question that I have is a simple matter of loops and how they work when they happen within functions such as grep.
This is my code:
for my $component ( split(/,/, $components_csv) ) {
if (grep { $_ eq $component } @url_components) {
push( @selected_components, $component);
next;
}
# ...
}
In this example, the next keyword: would take me to the next iteration of grep, or to the next iteration of the outer for loop? I could use a label to handle this, but I'm not sure if I need to.
As usual, this is about Someone Else's Code. Not in a blamey way, just that it seems to be my thing to trip over odd cases and bring them out for scrutiny by the good monks. Today I was successful in installing a module published by our good monk cavac, the CPAN module Array::Contains to a Gnu/Linux system, then a few minutes later I went to install it to my cygwin perl setup. I get an error that takes some scrunching up of one's eyes to figure out.
Simplest test case is a one-liner:
$ perl '-Mdiagnostics' -le 'print $diagnostics::VERSION'
couldn't find diagnostic data in /usr/share/perl5/5.40/pods/perldiag.p
+od /usr/share/perl5 /usr/local/lib/perl5/site_perl/5.40/x86_64-cygwin
+-threads /usr/local/share/perl5/site_perl/5.40 /usr/lib/perl5/vendor_
+perl/5.40/x86_64-cygwin-threads /usr/share/perl5/vendor_perl/5.40 /us
+r/lib/perl5/5.40/x86_64-cygwin-threads /usr/share/perl5/5.40 -e at /u
+sr/share/perl5/5.40/diagnostics.pm line 259, <POD_DIAG> line 718.
Compilation failed in require.
BEGIN failed--compilation aborted.
I don't see many modules that use diagnostics so this hasn't come up before for me.
Apr 16, 2025 at 02: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)
For several years now, I've used a home made RSS reader to collect and deal with my podcasts. You can see the full code here: github.
I just moved it to a new computer (Ubuntu 24.04, perl 5.38.2; the previous one was Ubuntu 22.04, perl 5.30.0) and suddenly it's failing to be interpret the RSS feeds that are working fine on the old machine.
It's failing on line 277, where it runs parse_string(), which is returning undef instead of the RSS object I get on the old machine, and I cannot work out what might be different to cause this. Any help would be gratefully appreciated.