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
Can't require MCE::Map (Strawberry)?
4 direct replies — Read more / Contribute
by Anonymous Monk
on Mar 07, 2025 at 02:20
    use strict; use warnings; use feature 'say'; use MCE::Map; MCE::Map-> init( chunk_size => 1, max_workers => 4, user_begin => sub { print "## ", MCE-> wid, " started\n"; }, user_end => sub { print "## ", MCE-> wid, " completed\n"; }, ); my @a = MCE::Map-> run( sub { $_ }, [ 0 .. 9 ]); print "\n", "@a", "\n"; say $MCE::VERSION;

    This, of course, prints:

    ## 1 started ## 3 started ## 2 started ## 4 started ## 1 completed ## 3 completed ## 2 completed ## 4 completed 0 1 2 3 4 5 6 7 8 9 1.882

    I want to make dependency on MCE, in my module, very optional i.e. triggered by rare circumstances only. Replacing "use" with "require" results in just first 4 lines of output and process running indefinitely, 4 cores fully loaded.

    MCE::Map being just a convenience, I can do this instead:

    use strict; use warnings; use feature 'say'; require MCE; my @in = ( 0 .. 9 ); my @out; my $mce = MCE-> new( chunk_size => 1, max_workers => 4, user_begin => sub { print "## ", MCE-> wid, " started\n"; }, user_end => sub { print "## ", MCE-> wid, " completed\n"; }, user_func => sub { MCE-> gather( $_ )}, input_data => \@in, gather => \@out, ); $mce-> run; say "@out"; $mce-> shutdown;

    And it runs perfectly. I understand I'll have to deal now with ordering of the output, it's not an issue. But that's the reason I was hoping to use MCE::Map to make it easier. Is this a bug?

    In general, is very optional (documented) dependency on something big and complex as MCE a bad-bad-bad idea? I guess I'll have to indicate minimum required MCE version then, which for example above would be... 1.500?

exit from $SIG{__DIE__} via a loop exit?
3 direct replies — Read more / Contribute
by ForgotPasswordAgain
on Mar 07, 2025 at 00:13
    %SIG says "When a __DIE__ hook routine returns, the exception processing continues as it would have in the absence of the hook, unless the hook routine itself exits via a goto &sub, a loop exit, or a die()". Presumably "continues as it would have in the absence of the hook" means it dies, but what does "the hook routine itself exits via ... a loop exit" mean? Attempts:
    $ perl -Mstrict -wE'$SIG{__DIE__}=sub{last}; die "hi"' Exiting subroutine via last at -e line 1. Can't "last" outside a loop block at -e line 1. # no strict $ perl -wE'$SIG{__DIE__}=sub{last}; die "hi"' Exiting subroutine via last at -e line 1. Can't "last" outside a loop block at -e line 1. # no warnings $ perl -E'$SIG{__DIE__}=sub{last}; die "hi"' Can't "last" outside a loop block at -e line 1. # -e instead of -E $ perl -e'$SIG{__DIE__}=sub{last}; die "hi"' Can't "last" outside a loop block at -e line 1. # put last in a while loop, dies $ perl -e'$SIG{__DIE__}=sub{while(1){last}}; die "hi"' hi at -e line 1. # put last in a non-loop block, dies $ perl -e'$SIG{__DIE__}=sub{{last}}; die "hi"' hi at -e line 1.
    Edit:
    $ perl --version This is perl 5, version 38, subversion 2 (v5.38.2) built for x86_64-ms +ys-thread-multi
ActiveState to Strawberry?
4 direct replies — Read more / Contribute
by dorianwinterfeld
on Mar 05, 2025 at 13:08
    Greetings Monks -

    I have a client that is thinking of switching from ActiveState Perl to Strawberry Perl. Do you know how heavy a lift this will be?

    Staying with Windows is a requirement. They have over a hundred CGI based apps that use Inline::Java and JDBC for database connectivity.

    Any advice/opinions would be appreciated.

Perl release v5.40.1 on a 32-bit box showing failed tests for atime and ctime in Time::HiRes
2 direct replies — Read more / Contribute
by Intrepid
on Mar 04, 2025 at 21:52

    This time I'll put the question first: "How worried should I be?" I set up a build of the most recent Debian archive of stable perl (v5.40.1) and saw the following failures in Time::HiRes:

    cwd: ~/build/perl/perl-debian-5.40/t
    Ran shell command:
       ./perl harness 2>&1 | egrep --color -i -e 'Fail' -
    Got output:

    -------------------------------------
    # Failed test 'atime set correctly'
    # Failed test 'mtime set correctly'
    # Failed test 'atime set correctly'
    # Failed test 'mtime set correctly'
    # Failed test 'File 1 atime set correctly'
    # Failed test 'File 1 mtime set correctly'
    # Failed test 'File 2 atime set correctly'
    # Failed test 'File 2 mtime set correctly'
    # Looks like you failed 8 tests of 22.
    Failed 8/22 subtests
    ../dist/Time-HiRes/t/utime.t (Wstat: 2048 (exited 8) Tests: 22 Failed: 8)
    Failed tests: 2-3, 5-6, 12-15
    -------------------------------------

    Perl release v5.40.1
    Module packed with Perl: Time::HiRes v1.9777
    Linux version 6.1.0-12-686
    Debian 6.1.52-1 (2023-09-07)

    I looked at http://matrix.cpantesters.org/ but I haven't learned to interpret the test matrix yet (I'm pleading ignorance when really I am probably just too distracted right now).

    Mar 05, 2025 at 02:47 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)

How to install Compress::Stream::Zstd in Strawberry Perl?
7 direct replies — Read more / Contribute
by cmv
on Mar 04, 2025 at 15:18
    Hi Monks-

    I'm asking for help installing Compress::Stream::Zstd in Strawberry Perl on a windows 10 box.

    Here is what I've done so far:

    1. Download & install fresh version of Strawberry Perl
    2. Ran in command window: perl -MCPAN -e shell
    3. Tried to install module: cpan> install Compress::Stream::Zstd

    It fails in the following way:

    cpan> install Compress::Stream::Zstd Running install for module 'Compress::Stream::Zstd' ... Building Compress-Stream-Zstd gcc -c -std=c99 -DWIN32 -DWIN64 -DPERL_TEXTMODE_SCRIPTS -DMULTIPLICITY + -DPERL_IMPLICIT_SYS -DUSE_PERLIO -D__USE_MINGW_ANSI_STDIO -fwrapv -f +no-strict-aliasing -mms-bitfields -Wall -Wextra -Wno-parentheses -Wno +-unused -Wno-unused-parameter -I. -Iext/zstd/lib -DZSTD_LEGACY_MULTIT +HREADED_API -Os -falign-functions -falign-jumps -falign-labels -falig +n-loops -freorder-blocks -freorder-blocks-algorithm=stc -freorder-blo +cks-and-partition "-DVERSION=\"0.206\"" "-DXS_VERSION=\"0.206\"" -I"C +:\STRAWB~1\perl\lib\CORE" -I"C:\STRAWB~1\c\include" -o "lib\Compress\ +Stream\Zstd.o" "lib\Compress\Stream\Zstd.c" ExtUtils::Mkbootstrap::Mkbootstrap('blib\arch\auto\Compress\Stream\Zst +d\Zstd.bs') Generating script 'lib\Compress\Stream\Zstd.lds' g++ "lib\Compress\Stream\Zstd.def" -o "blib\arch\auto\Compress\Stream\ +Zstd\Zstd.xs.dll" -Wl,--enable-auto-image-base -shared -s -L"C:\STRAW +B~1\perl\lib\CORE" -L"C:\STRAWB~1\c\lib" -L"C:\STRAWB~1\c\x86_64-w64- +mingw32\lib" -L"C:\STRAWB~1\c\lib\gcc\x86_64-w64-mingw32\13.2.0" "lib +\Compress\Stream\Zstd.lds" -pthread ext/zstd/lib/libzstd.a C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x +86_64-w64-mingw32/bin/ld.exe: cannot find ext/zstd/lib/libzstd.a: No +such file or directory collect2.exe: error: ld returned 1 exit status error building blib\arch\auto\Compress\Stream\Zstd\Zstd.xs.dll from "l +ib\Compress\Stream\Zstd.o" at C:/Strawberry/perl/lib/ExtUtils/CBuilde +r/Platform/Windows.pm line 241. ...
    I believe the problem is that it cannot find the ext/zstd/lib/libzstd.a library. Is there some place I can download this from (for x86_64), or build it myself? Once built, where do I put it so that the CPAN install can find it?

    Thanks in advance for any help on this!

    -Craig

    PS: Here is the complete CPAN output:

How to Install Lemmatize
2 direct replies — Read more / Contribute
by perlmike
on Mar 02, 2025 at 14:04

    I was trying to download Lingua::EN::Lemmatize, but cpan couldn't find it. Any suggestion will be greatly appreciated. Thanks!

Getting less output using prove's --merge option
2 direct replies — Read more / Contribute
by nysus
on Feb 28, 2025 at 09:28

    I'm trying to figure out why prove's --merge option gives me different output after running this test file:

    use strict; use warnings; use Test::More; ok 1; ok 0; done_testing();

    $PM = "Perl Monk's";
    $MC = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar Parson";
    $nysus = $PM . ' ' . $MC;
    Click here if you love Perl Monks

schwartzian transform problem - Solved
4 direct replies — Read more / Contribute
by Cristoforo
on Feb 27, 2025 at 14:37
    I wonder if someone could tell me why this code is not working. It is to sort the records from highest percent to lowest. (I edited the regexp in split) Found one error. the mao{$_[0]} should be map {$_->[0]} and the split needed a newline (\n) at the end of the pattern split(/(?<=workspace\/data)\n/, $s) Now, I'm getting the correct sorted output.
    C:\Old_Data\perlp>perl try3.pl >>> prd1702 Filesystem Size Used Avail Use% Moun +ted on /workspace 3.9T 746G 3.1T 23% /wor +kspace/data >>> prd1703 Filesystem Size Used Avail Use% Moun +ted on /workspace 3.9T 687G 3.2T 18% /wor +kspace/data >>> prd1701 Filesystem Size Used Avail Use% Moun +ted on /workspace 3.9T 887G 3.0T 13% /wor +kspace/data
    (Below, the code before fixes noted above)
    #!/usr/bin/perl use strict; use warnings; use feature 'say'; #https://stackoverflow.com/questions/79472778/sorting-the-content-of-a +-file my $s = <<EOF; >>> prd1701 Filesystem Size Used Avail Use% Moun +ted on /workspace 3.9T 887G 3.0T 13% /wor +kspace/data >>> prd1702 Filesystem Size Used Avail Use% Moun +ted on /workspace 3.9T 746G 3.1T 23% /wor +kspace/data >>> prd1703 Filesystem Size Used Avail Use% Moun +ted on /workspace 3.9T 687G 3.2T 18% /wor +kspace/data EOF my @data = map {$_[0]} sort {$b->[1] <=> $a->[1]} map {[$_, /\s(\d+)%/]} split(/(?<=workspace\/data)/, $s);
    It is printing error as:
    C:\Old_Data\perlp>perl try3.pl Use of uninitialized value in numeric comparison (<=>) at try3.pl line + 23. Use of uninitialized value in numeric comparison (<=>) at try3.pl line + 23.
remove chars with regex
5 direct replies — Read more / Contribute
by frank1
on Feb 26, 2025 at 04:09

    I need some help on removing the middle chars and leave the first 5 characters and last 5 characters using regex

    i want this output

    0x388c ... b19297

    but am getting this error Use of uninitialized value $_ in pattern match (m//)

    my $char = "0x388c818ca8b9251b393131c08a736a67ccb19297"; my($output) = $char = /^(?<=\S{5})\S(?=\S{7})/; print $output;
what should be in PERL5LIB after installing from source the 5.40.1 version on MacOS (am64)
1 direct reply — Read more / Contribute
by kwolcott
on Feb 21, 2025 at 23:28

    I'm really confused and frustrated about how to get my PERL5LIB environment variable set correctly.

    I'm on MacOS Sequoia, aarch64, running zsh, installed Perl 5.40.1 from source, into the /opt/perl_5.40.1 directory.

    I already have a Perl 5.38.2, also built from source, located in the /opt/perl directory.

    I have a MacPorts version of Perl installed (5.34.3). I removed an additional MacPorts Perl version 5.38.3 that I had installed recently.

    I was reading in the Programming Perl book about PERL5LIB...I don't understand the order of the paths that should be in the PERL5LIB.

    I've installed MANY Perl modules from CPAN using cpanm, specifying -L path respective to each version of Perl.

    I have a section in my ~/.zshrc for Perl that looks like this:

    I'm not using homebrew and I'm not using perlbrew.

    I was using Sidef (installing manually as a standalone executable, not as a Perl Module) for some while, then things went bonkers when I installed Perl 5.38.3 from MacPorts (I think). Now Sidef fails, and many Perl programs fail that require modules (some work, some fail).

    ./wagstaff_primes.pl Can't locate local/lib.pm in @INC (you may need to install the local:: +lib module) (@INC entries checked: /opt/perl_5.40.1/lib/site_perl/5.4 +0.1/darwin-2level /opt/perl_5.40.1/lib/site_perl/5.40.1 /opt/perl_5.4 +0.1/lib/5.40.1/darwin-2level /opt/perl_5.40.1/lib/5.40.1) at ./wagsta +ff_primes.pl line 4. BEGIN failed--compilation aborted at ./wagstaff_primes.pl line 4.

    The aforementioned is a script from Rosetta Code.

    find /opt/perl_5.40.1/lib -type f -name lib.pm /opt/perl_5.40.1/lib/5.40.1/darwin-2level/lib.pm /opt/perl_5.40.1/lib/lib/perl5/local/lib.pm

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.