New here?I want to ask a question of the Perl Monks. Where do I start?

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.

If you're new here, please read PerlMonks FAQ
and Create a new user!

Quests
poll ideas quest 2026
Starts at: Jan 01, 2026 at 00:00
Ends at: Dec 31, 2026 at 23:59
Current Status: Active
0 replies by pollsters
    First, read How do I create a Poll?. Then suggest your poll here. Complete ideas are more likely to be used.

    Note that links may be used in choices but not in the title.

Perl News
London Perl and Raku Workshop 2026 goes from Maybe to Likely
on Apr 27, 2026 at 09:01
0 replies by choroba
    The announcement

    Our love of Perl and Raku, means another London Perl and Raku Workshop is presently in the works for November 2026, with an exact date and venue to be confirmed in due course.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Linuxlinks on Perl Static Site Generators
on Feb 20, 2026 at 05:14
0 replies by mldvx4
Supplications
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?

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

PerlMonks Discussions
Moving the site behind a CDN
3 direct replies — Read more / Contribute
by Co-Rion
on Apr 26, 2026 at 04:43

    Thanks to main work by Leo Lapworth and Olaf Alders at the Perl Toolchain Summit, we now have a setup that allows us to move the site behind a CDN ( https://www.fastly.com/ in fact ). Fastly does not require magic Javascript to execute on the clients, but will ideally still help to stem the deluge of scrapers. Together with this, there will be some likely changes:

    The site will only be available under perlmonks.org. The other domains will issue HTTP redirects to that address. This means that you will have to check the hostnames in your tools and in your browsers. Using the hostnames to differentiate between user profiles will not work anymore.

    The site pages will be cached for Anonymous Monk. We'll start out with a cache duration of 1 hour but will likely increase this. Fastly has an API, so maybe busting the cache for recently updated threads is possible. If you are polling Perlmonks without a login, you will likely see a more static response.

    The timeline to move the site behind Fastly is to do it is likely in the next two to four weeks, depending on the availablility of myself and others.