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
Count assertions
3 direct replies — Read more / Contribute
by 1nickt
on Mar 10, 2026 at 05:20

    Hi all, with the following test file how do I get prove to report 6 (assertions) rather than 2 (subtests)?

    use Test::More; subtest foo => sub { ok 1; ok 2; ok 3; }; subtest bar => sub { ok 4; ok 5; ok 6; }; done_testing;

    Thanks!


    The way forward always starts with a minimal test.
An anomaly with Filesys::DfPortable, I need your eyes
2 direct replies — Read more / Contribute
by Intrepid
on Mar 09, 2026 at 14:47

    I'm getting an unexpected result from an attempt to use a module, Filesys::DfPortable, on CPAN. I'm seeing the same results in blocks, with different filesystems used as arguments to dfportable. The output of my code looks like this:

    $ perl ~/Documents/perl-libdirs-installTime.pl
    /usr/lib/perl5/5.40/x86_64-cygwin-threads  installarchlib
    Total 1k blocks used in installarchlib:  175,087,368
    /usr/share/perl5/5.40                      installprivlib
    Total 1k blocks used in installprivlib:  175,087,368
    

    So here's the code I'd like help with:

    #!/usr/bin/env perl # use strict; use warnings; use Config; use Number::Format qw(:subs); use Filesys::DfPortable; my $mlen = 0; my %hop; my @lodirs = qw(installarchlib installprivlib); for (@lodirs) { my $p = $Config{ $_ }; $mlen = length( $p ) > $mlen ? length( $p ) : $mlen; $hop{ $_ } = $p; } $mlen += 2; for (sort keys( %hop )) { printf( "%-${mlen}s%s\n", $hop{ $_ }, $_ ); my $mea = dfportable( $hop{ $_ }, 1024 ); printf "Total 1k blocks used in %s: %s\n", $_ , format_number( $mea->{bused} ); }

    I started working on this little script in Linux and I see the same anomalous results on CygPerl. I don't think it's a PEBKAC but I need other eyes to check it out. Thanks very much, Monks / Nuns.

        – Soren
    Apr 16, 2026 at 07: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 little overloading conundrum
2 direct replies — Read more / Contribute
by syphilis
on Mar 06, 2026 at 19:46
    Hi,

    I have a module A that overloads the '-' operator via its A::oload_minus() subroutine.
    And I have a second module B that also overloads the '-' operator via it's own B::oload_minus() subroutine.
    Both modules also have their own oload_add, oload_mul, oload_div, oload_mod and oload_pow subroutines that overload the other basic arithmetic operators).

    I have constructed the overloading in module A to handle B objects.
    But if module B's overloading subroutines are passed a module A object, it is (by my current design) a fatal error.
    use A; use B; $A_obj = A->new(16); $B_obj = B->new(6); my $n1 = $A_obj - $B_obj; # $n1 is an A object with value 10 my $n2 = $B_obj - $A_obj; # Fatal error
    In the above demo I want $n2 to be an A object, with the value of -10.
    That is, I want the A::oload_minus() sub to receive the args ($A_obj, $B_obj, TRUE).
    Instead, the B::oload_minus() sub is receiving the args ($B_obj, $A_obj, FALSE) - which is, by my current design, a fatal error since B::overload_minus() does not currently accept A objects.

    Is there a way that I can work around this without making any changes to the B module ? (The motivation to not alter module B is simply that I don't want to add more clutter to B unless I need to.)

    My module "A" is in fact Math::MPC, and my module "B" is in fact Math::MPFR.

    AFTERTHOUGHT: I should point out that the arithmetic overloading in the publicly available versions of Math::MPC don't yet accept Math::MPFR objects. (I've currently implemented this new feature on my local Math::MPC builds only.)

    Cheers,
    Rob
Type coercion and union
2 direct replies — Read more / Contribute
by tomred
on Mar 06, 2026 at 12:29

    I have the following Type defined.

    package Types; use v5.34; use warnings; use Type::Utils qw( as coerce declare from via ); use Types::Common qw( Enum Str ); use Type::Library -base, -declare => qw( CreditType InvoiceType ); declare InvoiceType, as Enum [qw/ ACCPAY ACCREC /]; coerce InvoiceType, from Str, via { #warn "Trying to coerce $_\n"; my %types = ( Invoice => 'ACCREC', SupplierInvoice => 'ACCPAY', ); #my $ret = $types{$_}; #warn "Returning $ret\n"; return $types{$_}; } ; declare CreditType, as Enum [qw/ ACCPAYCREDIT ACCRECCREDIT /]; coerce CreditType, from Str, via { warn "Trying to coerce $_\n"; my %types = ( Credit => 'ACCRECCREDIT', SupplierCredit => 'ACCPAYCREDIT', ); my $ret = $types{$_}; warn "Returning $ret\n"; return $types{$_}; } ; 1;

    I have a class that uses the types as a union, this or that

    package MyApp; use v5.34; use warnings; use Moo; use Types qw/ InvoiceType CreditType /; has 'type' => ( is => 'ro', isa => InvoiceType | CreditType, required => 1, coerce => 1, ); sub run { my ($self) = @_; say "Running with ".$self->type; } 1;

    I have a test to make sure it's doing what I expect `t/type.t`

    #!/opt/perl5/bin/perl use v5.34; use warnings; use Test::More; use Types qw( InvoiceType CreditType ); { subtest 'Type coercion' => sub { is InvoiceType->coerce('Invoice'), 'ACCREC', 'Can coerce a sales invoice'; is InvoiceType->coerce('SupplierInvoice'), 'ACCPAY', 'Can coerce a supplier invoice'; is CreditType->coerce('Credit'), 'ACCRECCREDIT', 'Can coerce a credit type'; is CreditType->coerce('SupplierCredit'), 'ACCPAYCREDIT', 'Can coerce a supplier credit type'; }; } { my $class = 'MyApp'; use_ok($class); subtest 'Class coercion' => sub { for my $t ( qw/Invoice SupplierInvoice Credit SupplierCredit / + ) { note "Type=$t"; my $x = new_ok($class => [ type => $t ]); note "Now Type=".$x->type; } }; } done_testing;
    t/type.t .. # Subtest: Type coercion ok 1 - Can coerce a sales invoice ok 2 - Can coerce a supplier invoice ok 3 - Can coerce a credit type ok 4 - Can coerce a supplier credit type 1..4 ok 1 - Type coercion ok 2 - use MyApp; # Subtest: Class coercion # Type=Invoice ok 1 - An object of class 'MyApp' isa 'MyApp' # Type=SupplierInvoice ok 2 - An object of class 'MyApp' isa 'MyApp' # Type=Credit not ok 3 - MyApp->new() died # Failed test 'MyApp->new() died' # at t/type.t line 31. # Error was: Undef did not pass type constraint "InvoiceType| +CreditType" (in $args->{"type"}) at /home/dpaikkos/spl/local/lib/perl +5/Test/More.pm line 741 # "InvoiceType|CreditType" requires that the value pass "Credi +tType" or "InvoiceType" # Undef did not pass type constraint "InvoiceType" # "InvoiceType" is a subtype of "Enum["ACCPAY","ACCREC"]" # "Enum["ACCPAY","ACCREC"]" requires that the value is def +ined # Undef did not pass type constraint "CreditType"

    I excel at leaving typos in my code but I am pretty sure there are none in the code so far. The coercions appear to work in a stand alone fashion but when used as a union, the 2nd Type does not appear to apply the coercion. If I swap the "CreditType" to be the first item, I find that the InvoiceType fails.

    I suspect I could use some kind of named parameterized coercion and `plus_coercions` but I hit this snag and haven't been able to move forward.

    Does anyone have any insights into what I'm doing wrong?

    Thanks in advance
WebPerl in a Progressive Web App?
1 direct reply — Read more / Contribute
by LanX
on Mar 06, 2026 at 08:52
    Hi

    Is it possible to run WebPerl inside a PWA?

    Hence effectively running Perl inside an app which can be installed on Android, Win, Linux?

    Has it been attempted yet?

    What are the results?

    Does it reduce the startup time of Perl because it's running hot in the background?

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

Tieing STDERR to a textbox causes the IPC::Run start function to fail
2 direct replies — Read more / Contribute
by CrashBlossom
on Mar 05, 2026 at 20:28
    Greetings Monks, I am running strawberry perl 5.30 under windows 11.

    When the program below reaches the start function, it fails with the seemingly nonsensical error "Can't locate auto/Tk/ROText/FILENO.al". Tieing only STDOUT to the same widget is no problem.

    Does anyone have any insight as to what is happening here?

    use warnings; use strict; use IPC::Run qw(start pump finish timeout); use Tk; require Tk::ROText; my $mw = MainWindow->new(-title => " NON BLOCKING"); my $outw = $mw->Scrolled('ROText', -font => "{Courier New} 10 bold", -background => 'DarkBlue', -foreground => 'OldLace', -scrollbars => 'se', -wrap => 'none', -width => 100, -height => 10, )->pack(-fill => "both", -expand => 1); + # tie *STDOUT, 'Tk::Text', $outw; tie *STDERR, 'Tk::Text', $outw; my ($in, $out, $err) = ('', '', ''); my $h; if (! defined(eval { $h = start ['cmd.exe', '/c', 'dir'], \$in, \$out, + \$err; })) { print "\nStart failed: $@\n"; } while($h->pumpable) { $h->pump; print $out; $out = ''; } $h->finish; MainLoop;
pp's tmp folder content execution
1 direct reply — Read more / Contribute
by DomX
on Feb 19, 2026 at 11:51

    Dear Monks, here monk Dominik, asking my siblings for wisdom.

    I'm a fan of using pp to make standalone programs since v5.40.0, because it lets me use the new Perls and doesn't mess the target system by installing anything by sudo cpan somewhere nobody is finding things again or making updates at all.

    Long story short: Delivering a pp archive is already pretty neat, but I'd like to go a step further. The application extracts itself to /tmp/par-<user name hash>/cache-<app hash or -T string> (or similar) by default. So, what I thought, to reduce the startup time, which is really poor for pp executables, compared to native Perl, I'd like to omit the extraction and verification step of the pp binary, but directly start the interpreter from the /tmp/par-.../cache-... directory, with the script as argument. Something I think the pp binary is doing. But the executables and libraries have very obscure names, so I don't know, what exact I need to execute to start up the interpreter from /tmp/par-.../cache-...

    Maybe I'm completely wrong on this path anyway and this is any magic within the pp binary itself, not just from this folder.

    So, what I actually try to achieve is: having a unpacked Perl interpreter, running my scripts, for example:

    $ cat /usr/bin/myapp #!/usr/bin/env bash /usr/libexec/myapp/perl /usr/libexec/myapp/myapp.pl "$@"

    I know, I could just compile a Perl residing entirely withing /usr/libexec/myapp, but maybe there is a more simple way to do so?

Strange behavior of POD online renderer https://metacpan.org/pod2html
1 direct reply — Read more / Contribute
by Darkwing
on Feb 19, 2026 at 11:48

    From time to time, I use https://metacpan.org/pod2html to check my POD. Recently, I noticed some strange behavior:

    The following code renders as expected:

    package FOO; use strict; use warnings; sub foo { my $str = shift; return $str if $str =~ /^ssh\@github-/; } 1; __END__ =head1 NAME Foo - The great Foo module

    But if i change the "return" line like this, simply adding a \. to the regexp:

    return $str if $str =~ /^\.ssh\@github-/;

    then i get "Error rendering POD - "

    The error disappears when i use parens:

    return $str if ($str =~ /^\.ssh\@github-/);

    Or, when i change the string "ssh" to something else, no error occurs:

    return $str if $str =~ /^\.sh\@github-/;

    No error with the line above!

    What's going on here? I would expect a POD renderer not to look at the active code at all. Is there perhaps a hidden feature that I'm conflicting with here?

IO::Prompter return object
2 direct replies — Read more / Contribute
by azadian
on Feb 17, 2026 at 16:47
    perl -MIO::Prompter -e '$ret = prompt -num,"number:" ; prompt -num,-de +f=>$ret, "another:"'
    IO::Prompter returns an object which gets auto-stringified, except when it doesn't...

    How can I explicitly extract the string/number from the object?

perl v
2 direct replies — Read more / Contribute
by Anonymous Monk
on Feb 16, 2026 at 04:56
    I accidentally typed perl v in the terminal and saw a strange message. I tried every letter and found that they all say something like Can't open perl script "z": No such file or directory except four special letters do something different does anyone know why?
    perl a (nothing happens) perl b (nothing happens) perl c Unrecognized character \xCF; marked by <-- HERE after <-- HERE near co +lumn 1 at c line 1. perl v Number found where operator expected (Do you need to predeclare "perl" +?) at v line 2, near "perl 5" syntax error at v line 2, near "perl 5" Execution of v aborted due to compilation errors.

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.