Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Seekers of Perl Wisdom

( [id://479]=superdoc: print w/replies, xml ) Need Help??

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
Faster (but uglier) PWC 350-2 solutions
2 direct replies — Read more / Contribute
by Anonymous Monk
on Dec 09, 2025 at 07:09

    TASK2: https://theweeklychallenge.org/blog/perl-weekly-challenge-350/#TASK2

    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:

    sub pwc { my ( $from, $to, $target ) = @_; use integer; my @witnesses = ([ 4, 7 ], [ 2 .. 9 ]); my ( %pairs, $j ); for ( my $i = ( $from + 2 ) / 3 * 3; $i <= $to; $i += 3 ) { my $i_key = join '', sort split '', $i; my $k = $i % 9 ? 0 : 1; for ( @{ $witnesses[ $k ]}) { last if length( $j = $i * $_ ) != length( $i ); $pairs{ $i }{ $j } = $_ unless $i_key ne join '', sort split '', $j } for ( @{ $witnesses[ $k ]}) { last if length( $j = $i / $_ ) != length( $i ); $pairs{ $i }{ $j } = -$_ unless $i % $_ || exists $pairs{ $j } && exists $pairs{ $j }{ $i } || $i_key ne join '', sort split '', $j } } return scalar grep { %$_ >= $target } values %pairs }

    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:

Perl::Critic versus File::Path
1 direct reply — Read more / Contribute
by mldvx4
on Dec 05, 2025 at 11:50

    Greetings O monks,

    I have turned perlcritic --stern towards several scripts I have and encountered a question. The manual page for File::Path contains the following excerpt:

    @created = make_path('foo/bar/baz', '/zug/zwang', { verbose => 1, mode => 0711, });

    Indeed, in my script(s) that syntax works fine, like this for example make_path($page,{mode=>0775})

    However, when I point perlcritic at the script(s), I get warnings like the following about how leading zeros should be avoided:

    Integer with leading zeros: "0775" at line 657, column 34. See page 58 of PBP. (Severity: 5)

    What is the right way to resolve that warning or error? Putting it in quotes does not have the desired effects.

    PS. Any tips on non-Amazon book sellers inside the EU which can sell a paper copy of PBP?

Benchmarking Perl's Net::Async::FastCGI app consistently return LOTS of "Non-2xx responses"
3 direct replies — Read more / Contribute
by Anonymous Monk
on Dec 04, 2025 at 15:04
    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/>
    which returns:
    ... 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" ...
    2. Nginx config:
    ==============================================================================
    location /helloworld/ { proxy_buffering off ; gzip off ; fastcgi_pass unix:/testFolder/myPath/myUDS.sock ; include fastcgi_params ; }
    3. helloworld test script:
    ==============================================================================

Windows, SBP, 'File::Copy::Recursive::Reduced' fails its tests due to permissions
1 direct reply — Read more / Contribute
by Intrepid
on Dec 01, 2025 at 22:22

    (SBP means "Strawberry Perl")

    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)
    
    

    I was not actually aiming to test or install File::Copy::Recursive::Reduced, but it was a dependency for Mouse.

    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)

A Very Fast 64–Bit Date Algorithm
3 direct replies — Read more / Contribute
by mldvx4
on Nov 26, 2025 at 14:04
Normalizing diacritics in (regex) search
4 direct replies — Read more / Contribute
by LanX
on Nov 24, 2025 at 06:39
    Hi

    I have the problem to find multilingual filenames, where diacritics are inconsistently used. °

    Of course I could do the normalization manually and map à á ä å ... -> a and so on.

    But I suppose that

    • I'm reinventing the wheel
    • there is consistent unicode attribute for this.¹
    • or a cpan module
    I already looked at the regex modifiers but couldn't find any "diacritics independent" similar to /i

    (The only remote possibility which comes to mind is a special locale doing the trick ...hmm)

    Thanks in advance!

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

    UPDATES

    °) Latin alphabet only in my case!

    ¹) compare Based on "a" (U+0061)

Forcing encryption for Filesys::SmbClient or alternatives?
No replies — Read more | Post response
by Anonymous Monk
on Nov 24, 2025 at 04:55

    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

    [global] client min protocol = SMB3 client smb encrypt = required

    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.

[SOLVED] Need advice how to diagnose the problem when syntax using MAX() is correct according to MySQL monitor, but errors out in DBI
8 direct replies — Read more / Contribute
by dissident
on Nov 21, 2025 at 10:03
    There is a simple database.
    root@localhost [project_db]> describe articles_table; +------------------------+--------------+------+-----+---------+------ +-+ | Field | Type | Null | Key | Default | Extra + | +------------------------+--------------+------+-----+---------+------ +-+ | db_art_id | bigint | YES | MUL | NULL | + |

    I need the highest article ID in the column "db_art_id".
    This works just fine from the console:
    root@localhost [project_db]> SELECT MAX(db_art_id) FROM articles_table +; [...] +----------------+ | MAX(db_art_id) | +----------------+ | 1 | +----------------+ 1 row in set (0.01 sec) root@localhost [project_db]>
    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.
Perl hashes and non-determinism
6 direct replies — Read more / Contribute
by Ratazong
on Nov 19, 2025 at 03:32

    Dear monks,

    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:

    foreach my $k sort { $hash{$a}{value} <=> $hash{$b}{value} } (keys %ha +sh)
    - 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

    foreach my $k sort { $hash{$a}{value} <=> $hash{$b}{value} } (sort key +s %hash)
    but that doesn't seem to be elegant to me ...

    Rata (waiting for enlightment)
How do I package up a Perl-TK app for macOS?
2 direct replies — Read more / Contribute
by perltux
on Nov 13, 2025 at 17:57
    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.

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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others having a coffee break in the Monastery: (2)
    As of 2025-12-12 22:15 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What's your view on AI coding assistants?





      Results (92 votes). Check out past polls.

      Notices?
      hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
      erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.