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
Perl Inheritance Not Working as Expected
1 direct reply — Read more / Contribute
by InfiniteSilence
on Apr 28, 2026 at 14:24

    So I write a response to this blogs.perl.org post titled, 'Who Tests the Tester? Me!!!' by lichtkind and almost as soon as I hit the submit button I take a closer look at my test and say, 'oops...I forgot to change the class to the new subclass...I'll just change that and rerun my tests. No problem...'

    t/01.t ............ ok t/hsltupletest.t .. 1/? # Failed test 'A is now between 0 and 360 since it is degrees' # at t/hsltupletest.t line 22. # Looks like you failed 1 test of 6. t/hsltupletest.t .. Dubious, test returned 1 (wstat 256, 0x100) Failed 1/6 subtests t/tupletest.t ..... ok Test Summary Report ------------------- t/hsltupletest.t (Wstat: 256 (exited 1) Tests: 6 Failed: 1) Failed test: 6 Non-zero exit status: 1 Files=3, Tests=12, 0 wallclock secs ( 0.08 usr 0.02 sys + 0.49 cusr + 0.07 csys = 0.66 CPU) Result: FAIL

    Denied!

    Debugging reveals something extremely strange...

    main::(./t/hsltupletest.t:8): my $prospectTupleRef = [qw~a b c~]; DB<1> n main::(./t/hsltupletest.t:10): my $tuple = HSLTuple->new($prospectT +upleRef, 'HSL'); DB<1> n main::(./t/hsltupletest.t:12): ok($tuple->is_valid($prospectTupleRe +f) == 0, "A B C is an array but not an HSL tuple"); DB<1> x $tuple 0 FakeTuple=HASH(0x5b2e6ee12a70) 'axes' => 3 'space_name' => 'HSL' 'tupledata' => undef DB<2>

    What? It says it is a FakeTuple even though I clearly used the HSLTuple! Unsurprisingly, it calls the is_valid() method of FakeTuple:

    main::(./t/hsltupletest.t:20): ok($tuple->is_valid([qw~361 62 99~]) + == 0 , "A must be between 0 and 360 since it is degrees"); DB<2> s FakeTuple::is_valid(FakeTuple.pm:34): 34: my ($self, $data2Check) = @_; DB<2> l 34==> my ($self, $data2Check) = @_; 35: my $result = 0; 36: for(0..2){$result++ if ($data2Check->[$_]=~m/\d+/ && 37 $data2Check->[$_] >= 0 && 38 $data2Check->[$_] <= 100)}; 39 40: return ( $result == $self->no_of_axes() ) ? 1 : 0; 41 } 42 43 # code (loosely) borrowed from Basis.pm DB<2>

    Why did it not use my derived class and call my overridden method?

    Celebrate Intellectual Diversity

parentheses missing in action
1 direct reply — Read more / Contribute
by Anonymous Monk
on Apr 28, 2026 at 14:15
    I'm using autodie so this seemed reasonable:
    open my $pipe, $cmds;
    
    But perl warns: Parentheses missing around "my" list at ...

    It works but it warns and I know why. All of the following work too and silence the warning:

    open (my  $pipe,  $cmds);
    open  my ($pipe), $cmds;
    open  my  $pipe, ($cmds);
    
    1. seems most correct.
    2. also seems correctish.
    3. what is going on here?
Where are the perldelta files for development releases?
1 direct reply — Read more / Contribute
by Anonymous Monk
on Apr 28, 2026 at 03:03
Interpolate variable into regexp at time of definition rather than execution, as a filter for Path::Iterator::Rule
2 direct replies — Read more / Contribute
by ecm
on Apr 27, 2026 at 15:27

    I am attempting to use a Path::Iterator::Rule "Custom rule subroutine".

    I have a regexp during the buildup of my rules, which determines whether the custom rule subroutine is used. If it indicates to use the subroutine, then its capture group $1 at this point holds some text that I want to match in the subroutine to filter for certain pathnames.

    With the naive approach, it seems that the $1 or $var variable in my regexp is only expanded at the time of the regexp/subroutine being run. At this point, the variable is no longer valid and could have been overwritten by some other value. Naive code:

    my $rule = Path::Iterator::Rule->new; if ($id =~ /^([0-9A-F]{2})/) { my $int = $1; $rule->and( sub { m#/INT $int# } ); }

    Resulting errors are many times this line:

    Use of uninitialized value $int in regexp compilation at [redacted]/proj/intlist/intlist.pl line 1167.

    I found that it appears to work if I use a "postponed" regular subexpression like so:

    my $rule = Path::Iterator::Rule->new; if ($id =~ /^([0-9A-F]{2})/) { my $int = $1; $rule->and( sub { m#/INT (??{ "$int" })# } ); }

    Is this a correct approach? Are there other ways to interpolate a variable at the time of adding the custom rule subroutine, so that the rule doesn't refer to the variable later but rather uses the text that it used to hold?

Is it OK for Time::HiRes::time() to report the time differently per thread?
4 direct replies — Read more / Contribute
by Anonymous Monk
on Apr 23, 2026 at 08:20

    I would expect all "next" times to be higher than "first" times (unless I messed it with semaphores), but on some invocations it is not the case. Why does this happen? This is Strawberry 5.42

    use strict; use warnings; no warnings 'void'; use threads; use Thread::Semaphore ; use Time::HiRes 'time'; my $t = time; my @s = map Thread::Semaphore-> new( 0 ), 1 .. 4; my @t = map async { my $id = threads-> tid - 1; $s[ $id ]-> down; sin for 1 .. 1e7; # work per thread printf "first, %d %.3f\n", $id, time - $t; $s[ $id ]-> up( 4 ); $_-> down for @s; printf "next, %d %.3f\n", $id, time - $t; }, 1 .. 4; sin for 1 .. 1e7; # initial work $_-> up for @s; $_-> join for @t; __END__ first, 2 1.824 first, 3 1.824 first, 1 1.824 first, 0 1.832 next, 1 1.826 next, 3 1.828 next, 2 1.832 next, 0 1.832
Modern Subroutine Signature Requires Perl Version
6 direct replies — Read more / Contribute
by InfiniteSilence
on Apr 21, 2026 at 10:01

    I feel like this question has been asked in the past but I could not find it in the search.

    So I am running this code snippet from Dave Cross' blog titled, Summarizing a Month of Git Activity with Perl (and a Little Help from AI) and I ran into a new feature of Perl -- subroutines that take named arguments. We had prototypes in the past but people said they were wonky so I avoided them for the most part.

    So here I am trying to use this thing and I start getting a weird error:

    #!/usr/bin/perl -w use strict; # LEARN: weird -- the method has named parameters ... since v5.36 sub commits_for_month ($repo, $since, $until) { my $cmd = sprintf( q{git -C %s log --since="%s" --until="%s" --pretty=format:"%%s"}, $repo, $since, $until ); my @commits = `$cmd`; chomp @commits; return @commits; } 1;

    I get...,

    llegal character in prototype for main::commits_for_month : $repo, $si +nce, $until at ./gitter.pl line 7. Global symbol "$repo" requires explicit package name (did you forget t +o declare "my $repo"?) at ./gitter.pl line 10. Global symbol "$since" requires explicit package name (did you forget +to declare "my $since"?) at ./gitter.pl line 10. Global symbol "$until" requires explicit package name (did you forget +to declare "my $until"?) at ./gitter.pl line 11. ./gitter.pl had compilation errors.

    My Perl version:

    This is perl 5, version 40, subversion 1 (v5.40.1) built for x86_64-li +nux-thread-multi ...

    When I look this up using Google's handy-dandy AI it tells me all about the normal way to get passed-in parameters in a subroutine and then tells me that this new syntax is available in v5.36. So I add,

    use v5.36;

    To my code and voila, the code compiles,

    perl -c ./gitter.pl ./gitter.pl syntax OK

    Dave's example didn't specify the version like this in his code. Is there something in my environment I am supposed to set to avoid this from happening?

    Celebrate Intellectual Diversity

Failed 2 tests on CygPerl for Test2::Harness; would a newer perl pass?
2 direct replies — Read more / Contribute
by Intrepid
on Apr 15, 2026 at 14:44

    I tried installing Test2::Harness and a couple tests failed. I am not totally understanding the output and if someone knowledgeable could interpret this for me I'd be grateful.

    
    
    Running make test for EXODIST/Test2-Harness-1.000170.tar.gz
    PERL_DL_NONLAZY=1 "/usr/bin/perl.exe" "-Iblib/lib" "-Iblib/arch" test.pl
    
      FAIL    job 46  +~find_in_updir
      PASS    job 46    + Found file in expected spot
      FAIL    job 46    + Found file in expected spot
      DEBUG   job 46    | t/unit/App/Yath/Util.t line 133
    (  DIAG  )  job 46    | +---------+----+-----------------------------------------------------------+
    (  DIAG  )  job 46    | | GOT     | OP | CHECK                                                     |
    (  DIAG  )  job 46    | +---------+----+-----------------------------------------------------------+
    (  DIAG  )  job 46    | | <UNDEF> | =~ | (?^:\/cygdrive\/c\/Users\/somia\/AppData\/Local\/Temp\/ya |
    (  DIAG  )  job 46    | |         |    | th\-149000\-j3p7oZ\/tmp\/FJbCQG\/17DQP5yPmV\/thefile$)    |
    (  DIAG  )  job 46    | +---------+----+-----------------------------------------------------------+
      PLAN    job 46    | Expected assertions: 2
                job 46    ^
    (  DIAG  )  job 46    Failed test 'find_in_updir'
    (  DIAG  )  job 46    at t/unit/App/Yath/Util.t line 134.
    
    -------------------------------------------------------------------------------------------
    
      FAIL    job 57  + /cygdrive/c/Users/somia/AppData/Local/Temp has correct permissions
      DEBUG   job 57    t2/tmp_perms.t line 36
    
    The following jobs failed at least once:
    +--------------------+-----------+--------------------+--------------------+
    | Job ID             | Times Run | Test File          | Succeeded Eventual |
    |                    |           |                    | ly?                |
    +--------------------+-----------+--------------------+--------------------+
    |                    |           |                    |                    |
    | 796D54CF-8067-1014 | 2         | t/unit/App/Yath/Ut | NO                 |
    | -B37C-A366FD41E411 |           | il.t               |                    |
    |                    |           |                    |                    |
    | 7973C25C-8067-1014 | 2         | t2/tmp_perms.t     | NO                 |
    | -B37C-A366FD41E411 |           |                    |                    |
    +--------------------+-----------+--------------------+--------------------+
    
    The following jobs failed:
    +---------------------------------+------------------------+---------------+
    | Job ID                          | Test File              | Subtests      |
    +---------------------------------+------------------------+---------------+
    | 796D54CF-8067-1014-B37C-A366FD4 | t/unit/App/Yath/Util.t | find_in_updir |
    | 1E411                           |                        |               |
    |                                 |                        |               |
    | 7973C25C-8067-1014-B37C-A366FD4 | t2/tmp_perms.t         |               |
    | 1E411                           |                        |               |
    +---------------------------------+------------------------+---------------+
    
                                        Yath Result Summary
    -------------------------------------------------------------------------------------------
         Fail Count: 2
         File Count: 91
    Assertion Count: 1996
          Wall Time: 632.81 seconds
           CPU Time: 1960.39 seconds (usr: 3.67s | sys: 1.70s | cusr: 459.45s | csys: 1495.57s)
          CPU Usage: 309%
        -->  Result: FAILED  <--
    
    yath exited with 256 yath exited with 256
    not ok 1 - Passed tests when run by yath (allow fork)
    not ok 2 - Passed tests when run by yath (no fork)
    
    -------------------------------------------------------------------------------------------
    
    My Perl and System characteristics:

    cygwin_nt-10.0-26200 - 3.7.0
    AMD Ryzen 5 4600H with Radeon Graphics (AuthenticAMD 3000MHz) x86_64
    Perl (/usr/bin/perl:
    This is perl 5, version 40, subversion 3 (v5.40.3) built for x86_64-cygwin-threads-multi
    

    Thanks, all.
        – Soren
    Apr 15, 2026 at 18:38 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)

metacpan fastapi can't find the Config module
3 direct replies — Read more / Contribute
by Anonymous Monk
on Apr 15, 2026 at 10:39
    I ran into this problem looking up module versions with fastapi on metacpan:
    % perl -MHTTP::Tiny -MJSON::PP -le 'print decode_json(HTTP::Tiny->new- +>get("https://fastapi.metacpan.org/v1/module/" . shift)->{content})-> +{version}' Encode 3.21 perl -MHTTP::Tiny -MJSON::PP -le 'print decode_json(HTTP::Tiny->new->g +et("https://fastapi.metacpan.org/v1/module/" . shift)->{content})->{v +ersion}' Config <NOTHING GETS PRINTED>
    Results from direct access:
    fastapi.metacpan.org/v1/module/Encode { "abstract" : "character encodings in Perl"... fastapi.metacpan.org/v1/module/Config { "code" : 404, "message" : "Not found" }
ExtUtils::Installed fails to find Catalyst because it doesn't have a .packlist
3 direct replies — Read more / Contribute
by Anonymous Monk
on Apr 15, 2026 at 10:27
    % perl -MExtUtils::Installed -le 'print for ExtUtils::Installed->new-> +files("Catalyst")' Catalyst is not installed at -e line 1. % perl -MModule::Metadata -le 'print Module::Metadata->new_from_module +("Catalyst")->{filename}' /perl5/perlbrew/perls/perl-5.42.0/lib/site_perl/5.42.0/Catalyst.pm
    Compare to module with a .packlist:
    % perl -MExtUtils::Installed -le 'print ExtUtils::Installed->new->pack +list("CGI")->packlist_file' /perl5/perlbrew/perls/perl-5.42.0/lib/site_perl/5.42.0/darwin-2level/a +uto/CGI/.packlist ls -l /perl5/perlbrew/perls/perl-5.42.0/lib/site_perl/5.42.0/darwin-2l +evel/auto/CGI -rw-r--r-- 1 user staff 1.3K Jan 2 00:34 .packlist drwxr-xr-x 3 user staff 96B Jan 10 05:23 Ajax drwxr-xr-x 3 user staff 96B Jan 10 05:24 Application drwxr-xr-x 3 user staff 96B Jan 10 05:32 Compress drwxr-xr-x 3 user staff 96B Jan 10 05:33 PSGI drwxr-xr-x 3 user staff 96B Jan 10 05:33 Prototype drwxr-xr-x 3 user staff 96B Dec 17 11:39 Simple drwxr-xr-x 3 user staff 96B Dec 17 11:39 Struct drwxr-xr-x 3 user staff 96B Dec 17 11:39 Wiki % ls -l /perl5/perlbrew/perls/perl-5.42.0/lib/site_perl/5.42.0/darwin- +2level/auto/Catalyst drwxr-xr-x 4 user staff 128B Apr 15 07:00 Action drwxr-xr-x 4 user staff 128B Apr 15 07:00 Controller drwxr-xr-x 3 user staff 96B Dec 17 11:46 Devel drwxr-xr-x 4 user staff 128B Apr 15 07:00 Engine drwxr-xr-x 3 user staff 96B Dec 17 11:46 Manual drwxr-xr-x 5 user staff 160B Dec 17 11:46 Plugin drwxr-xr-x 3 user staff 96B Dec 17 11:45 Runtime
Perlbrew fails to install perl but reports success
2 direct replies — Read more / Contribute
by Anonymous Monk
on Apr 14, 2026 at 13:16
    % perlbrew install -v perl-5.8.9 ... DB_File.xs:998:34: error: incompatible function pointer types assignin +g to 'u_int32_t (*)(const void *, size_t)' (aka 'unsigned int (*)(con +st void *, unsigned long)') from 'int (const void *, size_t)' (aka 'i +nt (const void *, unsigned long)') [-Wincompatible-function-pointer-t +ypes] info->db_HA_hash = hash_cb ; ^ ~~~~~~~ DB_File.xs:1041:36: error: incompatible function pointer types assigni +ng to 'size_t (*)(const DBT *, const DBT *)' (aka 'unsigned long (*)( +const DBT *, const DBT *)') from 'int (const DBT *, const DBT *)' [-W +incompatible-function-pointer-types] info->db_BT_prefix = btree_prefix ; ^ ~~~~~~~~~~~~ ... 308 warnings and 2 errors generated. make[1]: *** [DB_File.o] Error 1 make: *** [lib/auto/DB_File/DB_File.bundle] Error 2 perl-5.8.9 is successfully installed. % perlbrew list * perl-5.42.0 perl-5.38.2 % perlbrew install -v perl-5.24.4 ... # Failed test 25 - SHA for cpan/ExtUtils-MakeMaker/lib/ExtUtils/Liblis +t/Kid.pm matches stashed SHA at porting/customized.t line 105 # got "47d2fdf890d7913ccd0e32b5f98a98f75745d227" # expected "bfd2aa00ca4ed251f342e1d1ad704abbaf5a615e" porting/customized.t .............................................. Failed 1/181 subtests ... Test Summary Report ------------------- porting/customized.t (Wstat +: 0 Tests: 181 Failed: 1) Failed test: 25 porting/libperl.t (Wstat +: 7424 Tests: 0 Failed: 0) Non-zero exit status: 29 Parse errors: No plan found in TAP output Files=2410, Tests=850611, 515 wallclock secs (11.99 usr 2.72 sys + 13 +4.39 cusr 16.64 csys = 165.74 CPU) Result: FAIL make: *** [test_harness] Error 1 perl-5.24.4 is successfully installed. % perlbrew list * perl-5.42.0 perl-5.38.2
    Summary of my perl5 (revision 5 version 42 subversion 0) configuration:
       
      Platform:
        osname=darwin
        osvers=23.3.0
        archname=darwin-2level
        gccversion='Apple LLVM 15.0.0 (clang-1500.3.9.4)'
    
        PERLBREW_PERL="perl-5.42.0"
        PERLBREW_SHELLRC_VERSION="1.02"
        PERLBREW_VERSION="1.02"
    

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.