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.
my $fn = shift;
exit 1 if not defined $fn;
my $input = do {
open my $fh, "<", $fn or die "open failed";
local $/;
<$fh>
};
my $count = () = $input =~ m/mul\(\d{1,3},\d{1,3}\)/g;
print "Found $count matches.\n";
Which do more or less the same thing. Running both scripts on the same file, I found that the Python version runs a full second faster! 1.375s as opposed to Perl's 2.466s
I had always thought that Perl's regex and parsing performance was particularly strong compared to other languages, so this was a shocker for me. What is it that I am doing wrong? How can I make the Perl version run as fast as the one in Python?
Quick question, and dumb: are we supposed to be able to reach CPAN authors by emailing to AUTHOR@cpan.ORG? I tried it on myself an hour ago and there's no message in my inbox.
I'm trying to reach MICHIELB (Michiel Beijen) about test warnings in his module File::MimeInfo
But the script runs to completion without any other apparent issues.
If I just copy/paste the above code into a standalone script and hardcode the path to $myfile, the error doesn't occur.
If I add "use autodie;" to the top of the script, the script exits at the "close(MYFILE)" line with the following messages:
gzip: stdout: Broken pipe
Can't close filehandle 'MYFILE': '' at myscript.pl line 1014
If I don't close the filehandle, the error doesn't occur and it doesn't seem to cause any other problems in the script.
If I change the assignment to $myfile_timestamp to a constant as opposed to reading an attribute from the filehandle, the error is the same.
Does anyone know what could be causing the broken pipe error? Is there any way I can debug it further? Reading from the pipe seems to provide a workaround but I'm not sure why it's necessary. This same code structure (doing either a standard open/read for a non-gzipped file or a zcat pipe open for a gzipped file) is used elsewhere in the script and doesn't ever give a "broken pipe" error.
For my sins, I run a legacy 5.24 install on which I have built an app of 15 years standing. Recently I have discovered that my Microsoft Outlook integration needed to send scheduled emails breaks on Windows boxes with 64 bit Office installs, while it runs fine with 32 bit Office installs.
The exact error thrown is:
No type library matching "Microsoft Outlook" found at ../Perl/lib/Mail
+/Outlook.pm line 111
While there do appear to be plenty of people who've encountered this issue, I do have some constraints which is why their solutions might not apply to my situation. First, I am unfortunately not open to upgrading my installation. Given enough time, I'd love to do that but there's never enough time, especially when there are tight deadlines! Second, I do not have the ability to directly manually tinker with the Registry settings on the machines this application must run on, as local admin rights are locked down.
I'm definitely not afraid though of tinkering with the modules. There are no external dependencies I have to satisfy so it is my private playground to hack around as I like with.
Question: How would I go about finding the exact changes needed at the Module level (or even as calls in my code) to address this issue? I've taken a good look around the Meta CPAN site but am none the wiser (all I can see is file permission and version bumps). I still want the application to run with 32 bit Office installs as well as 64 bit Office installs.
I need to install our huge Perl/Tk application on a MacBook. It worked years ago, we even used a signed package so the users weren't supposed to do anything advanced like compiling C libraries themselves. Unfortunately, the old installer doesn't work anymore.
Does anyone know how to install Perl/Tk an a MacBook? A manual way is enough for now, I'll try to find a way to automate it later.
Google finds lots of guidelines but most of them seem rather dated.
I hope it would be easier than rewriting all those several hundred thousand lines to a different GUI.
I’m writing a utility to go through my personal perl lib to ensure consistency across files. For example, I will use it to check each file has a comment containing the file’s path. So the utility will be going through and repeatedly searching a lot of text files.
There will be hundreds of documents searched repeatedly for certain strings of text. Rather than reinvent the wheel, I hunted around for a module that would help ensure the search was done efficiently both in terms of time and resources used so I don’t have to burden myself with worrying about the many small details. For example, the easiest thing for me to do would be to load all files into memory and simply search, write them back out to disk, load them all back into memory, search, save, repeat. Though this is easy, it’s obviously not efficient and I was hoping to find a module that would smartly determine how to handle this problem.
But I have searched around a bit and have come up empty. Does anyone have any recommendations?
$PM = "Perl Monk's";
$MC = "Most Clueless FriarAbbotBishopPontiffDeaconCuratePriestVicar Parson";
$nysus = $PM . ' ' . $MC; Click here if you love Perl Monks
I have a command-line download tool that extracts a list of filenames/urls upon which to operate. I added support to filter the list by accepting regex strings from --accept and --reject options. What I have works, but feels off because of the string eval. Is there another approach to this?
GetOptions(
'accept|a=s' => \my @accept,
'reject|r=s' => \my @reject,
) or die "Error with options\n";
my @filter = map eval "sub { \$_[0] =~ /$_/ }", @accept;
push @filter, map eval "sub { \$_[0] !~ /$_/ }", @reject;
# my @input = ([url, filename], ...);
my @filtered = filter(@input);
sub filter {
return unless @filter;
return map $_->[0],
grep { my $f = $_; all { $_->($f->[1]) } @filter } @_;
}
I'm going to go ahead and ask for help even though I know the problem may be a fubar'd system. I'm setting up pinto and am trying my first "pull" from CPAN, and getting an error:
Failed to mirror https://cpan.perl.org/modules/02packages.details.txt.gz: 501 Protocol scheme 'https' is not supported (LWP::Protocol::https not installed)
Thing is, LWP::Protocol::https certainly is installed, as are the dependencies Net::SSLeay and IO::Socket::SSL. Is it something pinto is doing, manipulating @INC or otherwise causing this failure?
Thank you again (I seem to post in SoPW once a week these days!), good Monks.
Mar 17, 2025 at 01:50 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)
I'm looking for a Perl module making it easy to implement a Web-based system where user can create accounts, changing passwords, recovering, etc. Any recommendations?