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.

Post a new question!

User Questions
Module to deal with PGP-encrypted email messages in 2025
1 direct reply — Read more / Contribute
by Nocturnus
on Aug 07, 2025 at 13:16

    Dear well-respected monks,

    I was wandering in the darkest night without any hope and orientation, but finally saw the promising lights of the monastery. The heart began to beat again, and I dare to ask you for your wisdom regarding the following question:

    I need to deal with PGP-encrypted email messages. To be precise, I would like to permanently decrypt thousands of PGP-encrypted email messages that I have on disk in the form of .eml files.

    To my surprise, I haven't found a PGP module for Perl that actually is usable in 2025 with recent Perl versions. Mail::PGP Mail::GPG seemed like a good candidate, but I now have lost nearly two days with trying to install it using CPAN in three different environments (Cygwin, Strawberry Perl / Native Windows and Linux). It seems that it cannot be used with recent Perl versions any more; no wonder that I've failed in trying to make it work.

    Then there is Mail:GnuPG. It seems to be the predecessor of Mail:PGP, seems to contain some bugs, and seems to be even more outdated. I managed to install it under Linux, but failed to install it under Cygwin and under Strawberry Perl. The latter would not be the key point, but for certain reasons it would simply be more comfortable for me to run the script under native Windows. At least, Mail::GnuPG could be the last resort.

    I am quite sure that I have missed something. What module would you, dear monks, use nowadays to decrypt PGP-encrypted email messages?

    To avoid misunderstandings:

    This question is about email messages that mostly contain nested MIME structures. When decrypting, all mail headers, MIME parts and attachments of the respective message should be preserved or decrypted, respectively. This means that I cannot use the Perl modules that can handle PGP on ordinary files; that would indeed be a no-brainer.

    Furthermore, I could use the GnuPG application directly to permanently decrypt those messages; I have verified that this is possible in general. However, when doing this, the mail headers of the original message do not exist any more in the decrypted version. Instead, the decrypted version contains the headers that were in the encrypted part of the original message. For example, the Date header gets lost; funnily enough, it exists only as a non-encrypted header in the original message.

    When anything else fails, I'll eventually take that route: Decrypt using the GnuPG application directly, then merge the headers from the original message with those of the decrypted message. As mentioned above, I'd like to listen to the monks before I take that effort.

    Your devoted novice Nocturnus

Bluetooth LE?
1 direct reply — Read more / Contribute
by cavac
on Aug 05, 2025 at 04:37

    I'm trying to connect to a Bluetooth LE (low energy) device, specifically the MXTP-100 printer (that extremely cheap thermal printer with the cat ears). I tried Net::Bluetooth, but that doesn't seem to support Low Energy devices.

    I can connect and print just fine to an old Epson bluetooth printer (not LE), but newer LE devices don't seem to work with Net::Bluetooth.

    To be honest, i have absolutely no idea what i'm doing. Does anyone have any suggestions?

    EDIT: Ooops, sorry, forgot to include my test code:

    (I just hacked one of the examples, so code quality is low. Also please ignore the mentioning of GPS, i just didn't bother to update all variable names and comments)

    PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
    Also check out my sisters artwork and my weekly webcomics
Possessive sub-pattern with non-greedy content + recursion: WHY does this work??
3 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 04, 2025 at 11:42

    Say, a string has embedded palindromes (PD); a PD in this case has odd (at least 3) number of letters. I want a piece of code to be executed exactly once for every PD including nested ones. Let "piece of code" be 'say'. Regex to extract a PD is well-known, and of course TIMTOWTDI, the question is not how to better solve the task.

    Almost accidentally I found a solution, which I'm puzzled about. I don't know if it could be a simpler SSCCE without recursion.

    say 'match' if 'abABCDCBAdeXYZYXfg' =~ / (?>^.*?) ( ( (.)(?-3)\g-1 | (.).\g-1 ) (?{ say $2 }) ) /x;

    Output:

    YZY XYZYX CDC BCDCB ABCDCBA

    Bingo, just what I need. Match fails -- it's irrelevant. But HOW? If either of the following is removed: (1) "^" anchor; (2) independence (s/>/:/), or (3) entire 1st pair of parens, then there are multiple visits to each PD i.e. not what I want. In fact, for (3) the PD groups are also visited in reversed order, this I don't understand neither. And why both PD groups (not only 1st one) are visited.

    Being greedy (s/\*\?/*/) produces no output, this I understand (I hope).

    If, in case of code above i.e. without removing anything, the engine gives characters back one by one (I thought this is how backtracking works) before it ultimately fails when it (suddenly, somehow) remembers about independence, then I'd expect YZY is found and said; and then XYZYX is found and embedded code executed for both YZY and XYZYX, i.e. both are said (i.e. YZY said twice in total).

    P.S. I've seen "Embedded Code Execution Frequency" section in perlre.

Documentation for ->&
2 direct replies — Read more / Contribute
by ikegami
on Aug 03, 2025 at 13:40
Running multi task
1 direct reply — Read more / Contribute
by joyfedl
on Aug 02, 2025 at 14:46

    I have a sample data, my question is that what is the best way to run multi-task, the URL API Endpoint is the one which is different but the tasks are the same like

    my $url = "https://v3.football.api-sports.io/fixtures?live=1"; my $url = "https://v3.football.api-sports.io/fixtures?live=2"; my $url = "https://v3.football.api-sports.io/fixtures?live=3";

    i was thinking on that this could work after code block i put continue Loop then other code block

    my problem is that i don't want to make multiple files which does same work, i want to include them in same file and run once

    #!/usr/bin/perl -wT use strict; use warnings; use LWP::UserAgent; use HTTP::Request; use JSON; use DBI; my $host = ""; my $usr = ""; my $pwd = ""; my $dbname = ""; my $dbh = DBI->connect("DBI:mysql:$dbname:$host", $usr, $pwd, { AutoCommit => 1, RaiseError => 1, }) or die $DBI::errstr; my $url = "https://v3.football.api-sports.io/fixtures?live=1"; my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new(GET => $url); $req->header('x-rapidapi-host' => 'v3.football.api-sports.io'); $req->header('x-rapidapi-key' => 'e73299760f882d'); my $response = $ua->request($req); my $parse_json = JSON::XS->new->decode ($response->content); if ($response->is_success) { for my $match (@{$parse_json->{response}}) { my $elapsed = $match->{fixture}{status}{elapsed}; my $status = $match->{fixture}{status}{short}; my $home = $match->{teams}{home}{name}; my $away = $match->{teams}{away}{name}; my $ht_home = $match->{score}{halftime}{home} // 'N/A'; my $ht_away = $match->{score}{halftime}{away} // 'N/A'; my $ft_home = $match->{score}{fulltime}{home} // 'N/A'; my $ft_away = $match->{score}{fulltime}{away} // 'N/A'; my $query = $dbh->prepare("# MYSQL QUERY"); $query->execute(); my $query_data = $query->fetchrow_array; $query->finish; # more select below............. if (int($elapsed > 0)) { my $Create = $dbh->prepare("# MYSQL QUERY) VALUES()"); $Create->execute(); $Create->finish(); } # more insert below............. } } else { print $response->status_line; } $dbh->commit; $dbh->disconnect;
New release of Text::CSV_XS won't build on Windows, prob a gcc input error (CygwinPerl)
3 direct replies — Read more / Contribute
by Intrepid
on Aug 01, 2025 at 17:41

    I'm at it again: reveling in debugging the build of Someone Else's Code ;-). In this case, Someone is H. Merijn Brand with his recent release of Text::CSV_XS on CPAN.


    EDIT

    I don't want to give a false impression of my motivations, and where I wrote above that I "revel in debugging ..." I could be misunderstood. I don't take pleasure in calling anyone out for lack of skill, lack of knowledge, or carelessness. Rather, I revel in having a problem I can apply my own efforts to solving while seeing contributions from my fellow nuns and monks who spot things that I have missed. The collaboration is what I revel in. Thanks, now back to the matter at hand.


    Looking closely at the compiler-related messages below, two things stand out as strange (see below in the "On Cygwin Perl..."):

    -ffile-prefix-map=/mnt/share/cygpkgs/perl/perl.x86_64/build=/usr/src/debug/perl-5.40.2-1

    -and-

    -ffile-prefix-map=/mnt/share/cygpkgs/perl/perl.x86_64/src/perl-5.40.2=/usr/src/debug/perl-5.40.2-1

    I don't have those paths, and self-evidently anything that starts with /mnt/ is not going to be portable, anyhow.

    What happens on Gnu/Linux:

    cp CSV_XS.pm blib/lib/Text/CSV_XS.pm Running Mkbootstrap for CSV_XS () chmod 644 "CSV_XS.bs" "/usr/local/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- CSV_ +XS.bs blib/arch/auto/Text/CSV_XS/CSV_XS.bs 644 "/usr/local/bin/perl" "/usr/local/lib/perl5/site_perl/ExtUtils/xsubpp" + -typemap '/usr/local/lib/perl5/5.40.1/ExtUtils/typemap' CSV_XS.xs +> CSV_XS.xsc mv CSV_XS.xsc CSV_XS.c cc -c -D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe +-fsORTIFY_SOURCE=2 -O2 -DVERSION=\"1.61\" -DXS_VERSION=\"1.61\" -fP +IC "-I/usr/local/lib/perl5/5.40.1/i686-linux-gnu-thread-multi/CORE" + CSV_XS.c rm -f blib/arch/auto/Text/CSV_XS/CSV_XS.so cc -shared -O2 -L/usr/local/lib -fstack-protector-strong CSV_XS.o - +o blib/arch/auto/Text/CSV_XS/CSV_XS.so \ \ chmod 755 blib/arch/auto/Text/CSV_XS/CSV_XS.so Manifying 1 pod document

    On Cygwin Perl 5.40.2 with gcc 13.4.0 what happens:

    [MSG] [Thu Jul 31 18:03:07 2025] Checking if your kit is complete... Looks good Generating a Unix-style Makefile Writing Makefile for Text::CSV_XS Writing MYMETA.yml and MYMETA.json [MSG] [Thu Jul 31 18:03:07 2025] DEFAULT 'filter_prereqs' HANDLER RETU +RNING 'sub return value' [ERROR] [Thu Jul 31 18:03:23 2025] MAKE failed: No such file or direct +ory cp CSV_XS.pm blib/lib/Text/CSV_XS.pm Running Mkbootstrap for CSV_XS () chmod 644 "CSV_XS.bs" "/usr/bin/perl.exe" -MExtUtils::Command::MM -e 'cp_nonempty' -- CSV_XS +.bs blib/arch/auto/Text/CSV_XS/CSV_XS.bs 644 "/usr/bin/perl.exe" "/usr/local/share/perl5/site_perl/5.40/ExtUtils/xs +ubpp" -typemap '/usr/share/perl5/5.40/ExtUtils/typemap' CSV_XS.xs > + CSV_XS.xsc mv CSV_XS.xsc CSV_XS.c gcc -c -U__STRICT_ANSI__ -D_GNU_SOURCE -ggdb -O2 -pipe -Wall -Werror +=format-security -D_FORTIFY_SOURCE=3 -fstack-protector-strong --param +=ssp-buffer-size=4 -ffile-prefix-map=/mnt/share/cygpkgs/perl/perl.x86 +_64/build=/usr/src/debug/perl-5.40.2-1 -ffile-prefix-map=/mnt/share/c +ygpkgs/perl/perl.x86_64/src/perl-5.40.2=/usr/src/debug/perl-5.40.2-1 +-fwrapv -fno-strict-aliasing -DUSEIMPORTLIB -O3 -DVERSION=\"1.61\" +-DXS_VERSION=\"1.61\" "-I/usr/lib/perl5/5.40/x86_64-cygwin-threads/C +ORE" CSV_XS.c rm -f blib/arch/auto/Text/CSV_XS/CSV_XS.dll g++ --shared -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,- +-enable-auto-image-base -fstack-protector-strong CSV_XS.o -o blib/a +rch/auto/Text/CSV_XS/CSV_XS.dll \ /usr/lib/perl5/5.40/x86_64-cygwin-threads/CORE/cygperl5_40.dll -lpth +read -ldl -lcrypt \ make: *** [Makefile:484: blib/arch/auto/Text/CSV_XS/CSV_XS.dll] Aborte +d make: *** Deleting file 'blib/arch/auto/Text/CSV_XS/CSV_XS.dll' [ERROR] [Thu Jul 31 18:03:23 2025] Unable to create a new distribution + object for 'Text::CSV_XS' -- cannot continue

    If anyone running CygPerl on Windows gets a different result trying to build Text::CSV_XS, please let me know in the thread, thanks.

        - Soren

    Aug 01, 2025 at 21:39 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)

passing newline in string argument
3 direct replies — Read more / Contribute
by Special_K
on Aug 01, 2025 at 14:49

    I have the following perl script:


    #!/usr/bin/perl -w use strict; use Getopt::Long; my $string; GetOptions( "string=s" => \$string ); printf("string = $string\n");

    I have the following shell script that calls the above perl script:


    #!/bin/tcsh /home/perl_scripts/pass_newline_as_text.pl \ -string 'foo\nbar'

    The output I would like to see is as follows:


    string = foo bar

    The actual output I'm seeing is the following:


    string = foo\nbar

    Is there a way to have the '\n' interpreted as an actual newline character by the perl script? I've tried enclosing the string in single and double quotes, and using 1-3 backslash escapes on the 'n' character but none of those work.

how do you determine which module needs to be updated while using perlbrew?
5 direct replies — Read more / Contribute
by Anonymous Monk
on Jul 31, 2025 at 22:41
    I'm using perlbrew, recently installed 5.42 using "perlbrew install stable". Now some programs don't work any more. For example, the error message says the version doesn't match for XS.c. How do you find out which module it means?
    perl -E 'use namespace::clean' Perl API version v5.40.0 of XS.c does not match v5.42.0
    perl -v This is perl 5, version 42, subversion 0 (v5.42.0) built for x86_64-li +nux Copyright 1987-2025, Larry Wall
    i tried looking in ~/.cpan/work to find a XS.c file, found one in the build for List::MoreUtils::XS. try to get cpanm to install List::MoreUtils and it provides the error as the reason it can't install:
    Checking whether perlapi is accessible... Perl API version v5.40.0 of +XS.c does not match v5.42.0-> N/A -> FAIL Configure failed for List-MoreUtils-0.430.
Purpose of the "caret" character in "qr" regex output
2 direct replies — Read more / Contribute
by roho
on Jul 30, 2025 at 21:09
    My environment: Perl 5.24.1 on Windows 10.

    The following SSCCE uses the "qr" operator to quote a string as a regular expression. The non-capturing part of the regex curiously has a "caret" inserted between the question mark and the colon. I've looked and can find no explanation or example of what the "caret" does in the regex produced by "qr". The "caret" does NOT (thankfully) anchor the regex at the beginning of the line, so what does it do?

    #!/usr/bin/perl use strict; use warnings; my $text = 'abcd'; my $regex = qr/$text/; print "\n\$text = |$text| \$regex = |$regex|\n\n"; __END__ Output: $text = |abcd| $regex = |(?^:abcd)|

    "It's not how hard you work, it's how much you get done."

Win32 unthreaded perl builds: To USE_MULTI or not ?
3 direct replies — Read more / Contribute
by syphilis
on Jul 30, 2025 at 07:55
    In the past, when I've built unthreaded perls on MSWindows, they have been built without defining USE_IMP_SYS and without defining USE_MULTI. There was no readily available option to do otherwise.
    However, as of a few days ago, building unthreaded bleadperl with both USE_MULTI and USE_IMP_SYS defined has been facilitated.

    Which option do I want ? Do I want (unthreaded) MSWin32-x64-multi or do I want (unthreaded) MSWin32-x64-perlio ?
    What are the pros and cons ?

    Cheers,
    Rob

Add your question
Title:
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":


  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.