Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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
Regex profiler
3 direct replies — Read more / Contribute
by phizel
on Jan 17, 2026 at 14:02
    Does a profiler exist for regular expressions? The only thing I could find was re's debug mode, but the output isn't very intuitive. I am imagining something like Devel::NYTProf with flame graphs indicating which sections of a regex need optimizing. Take the common whitespace trimming example s/^\s+|\s+$//g; it turns out to sub-optimal because the alternation negates the anchor optimization. Since I can't make heads or tails of re's debug mode output, the only tool in my toolbox for diagnosing regexen is to compare runtimes with Benchmark. Since regular expressions are a feature of many other languages, a better solution might even exist outside of perl.
Is getting locks on files with NFS broken on CygPerl?
2 direct replies — Read more / Contribute
by Intrepid
on Jan 17, 2026 at 13:56

    Hello good monks and nuns. I'm in the build directory for the distribution File::NFSLock working on installing it as I'm doing with hundreds of modules I've made a bundle of on one machine, getting them put in place on a new machine (finally figured out how that works). The tests in File-NFSLock stagger to a halt, freezing up in the code shown below, which is in t/120_single.t

    Is it possible that the lock operations are breaking because I have the build directories for these modules on a FAT32 filesystem, rather than NTFS? Wild guess.

    # Blocking Exclusive test within a single process (no fork) use Test::More tests => 2; use File::NFSLock; use Fcntl qw(O_CREAT O_RDWR O_RDONLY O_TRUNC LOCK_EX); use File::Temp qw(tempfile); my $datafile = (tempfile 'XXXXXXXXXX')[1]; # Create a blank file sysopen ( my $fh, $datafile, O_CREAT | O_RDWR | O_TRUNC ); close ($fh); ok (-e $datafile && !-s _); # Wipe any old stale locks unlink "$datafile$File::NFSLock::LOCK_EXTENSION"; # Single process trying to count to $n my $n = 20; for (my $i = 0; $i < $n ; $i++) { # <-- we never see output after thi +s point in the code (Soren) my $lock = new File::NFSLock { file => $datafile, lock_type => LOCK_EX, }; sysopen(my $fh, $datafile, O_RDWR); # Read the current value my $count = <$fh>; # Increment it $count ++; # And put it back seek ($fh,0,0); print $fh "$count\n"; close $fh; } # Load up whatever the file says now sysopen($fh, $datafile, O_RDONLY); $_ = <$fh>; close $fh; chomp; # It should be the same as the number of times it looped is $n, $_; # Wipe the temporary file unlink $datafile;

    I'm using CygPerl v5.40.3 (5.040003), on Windows 11. I am testing File::NFSLock 1.29. Do any of my good friends in the Cygwin camp here at Perlmonks get the same result? I checked RT @ cpan.org and didn't see any tickets that would apply to what's happening.

        — Soren

    EDIT

    I ran a test on my first system, that is, the one that the mentioned Bundle:: file came from; it's also Windows 11. The same CygPerl version. Guess what the result was ... yeah, the tests all passed. I have a significant amount to think about from the two (right now) replies below (thanks guys). But before immersion in NFS lore I thought I'd just try that. I have no theories at the moment. I will note, Alexander, that I don't recall ever choosing to install File::NFSLock on my computer. I think something I knowingly meant to install had a dependency on it.

    Jan 18, 2026 at 22:04 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 portable is the random number generator?
4 direct replies — Read more / Contribute
by Anonymous Monk
on Jan 11, 2026 at 00:30

    i tested a program under 5.42 and 5.38 and it worked the same on both versions. on how many computers would this program produce the expected output?

    /usr/bin/perl -v This is perl 5, version 38, subversion 2 (v5.38.2) built for x86_64-li +nux-gnu-thread-multi /usr/bin/perl -E 'srand(80085);say(join("",map({g($_)}("3f5a6471135061 +5c5b4f5867114c5666521f59535b604e57"=~m/../g))));sub g($num){chr(hex($ +num)+int(rand(31)));}' Just another Perl hacker
    perl -v This is perl 5, version 42, subversion 0 (v5.42.0) built for x86_64-li +nux perl -E 'srand(80085);say(join("",map({g($_)}("3f5a64711350615c5b4f586 +7114c5666521f59535b604e57"=~m/../g))));sub g($num){chr(hex($num)+int( +rand(31)));}' Just another Perl hacker
Warn if STDIN pipe is missing or unwanted
3 direct replies — Read more / Contribute
by Anonymous Monk
on Jan 10, 2026 at 20:56

    I have a script that can accept input from STDIN, but only if the proper option is specified (-i -). I want the script to warn if STDIN is not specified but the script is being piped to (echo test | ./script.pl) or if input is redirected (./script < input.txt). I also want it to warn in the opposite case, where STDIN is specified, but the script is not being piped or input is not redirected.

    I can detect if STDIN is a pipe with -p STDIN and if STDIN is redirected using (stat STDIN)[0] != 0, but when the script is run under cron, STDIN is a pipe even if the command is not being piped to. The only case under cron where STDIN is not a pipe is if it is redirected input. And testing if STDIN is empty is inadequate, because it's possible that the writing command in a pipeline will not have any output.

    Is it possible to do what I'm attempting, or is a bad idea?

    use Getopt::Long qw(:config bundling); GetOptions('input-file|i=s' => \my @file); my ($stdin_is_redir, $want_stdin) = !! (stat STDIN)[0]; for my $arg (@file) { my $fh; if ('-' eq $arg) { $want_stdin = 1; # This is never triggered under cron. warn "stdin isn't connected- missing pipe?\n" and next unless -p STDIN or ($stdin_is_redir and ! -t STDIN); $fh = *STDIN{IO}; } else { require Path::Tiny; my $file = path($arg); $fh = eval { $file->openr } or warn "$file: $@->{err}\n" and n +ext; } # do_something($_) while <$fh>; } # This is always triggered under cron unless $stdin_is_redir warn "stdin is connected, missing `-i -`?\n" if ! $want_stdin and ! -t STDIN and ($stdin_is_redir or -p STDIN); # Tested with: # ./script.pl # ./script.pl -i - # ./script.pl -i /dev/null # ./script.pl -i - < /dev/null # echo test | ./script.pl # echo test | ./script.pl -i -
perlbrew clone-modules fails to install lots of modules
3 direct replies — Read more / Contribute
by Anonymous Monk
on Jan 10, 2026 at 04:14
How to write in a non-form field of which the xpath is known using WWW::Mechanize::Chrome ?
1 direct reply — Read more / Contribute
by garo
on Jan 08, 2026 at 01:42

    I use WWW::Mechanize::Chrome but I can't manage to write in a <input>-field that's not inside a form.
    According to the docs I need the set_field() method. Maybe it also works with the get_set_value() method but I have no idea here either...

    If we assume that the only thing I know about the input-field is that it has the attribute id="foo" and that their is only one of these fields, how can I do this ?
    The only progress I made so far is that I managed to create a WWW::Mechanize::Chrome::Node object with $node = $mech->xpath('//input[@id="foo"]', single => 1);

I wrote an expression parser for PPI
1 direct reply — Read more / Contribute
by BerntB
on Jan 07, 2026 at 07:35
    Hi all,
    I could use some wisdom from the esteemed monks regarding a mildly insane hobby project of mine.

    PPI does not parse expressions into an AST, nor does it assign list/scalar/null context. I’ve implemented that myself and put the code here: https://github.com/Percolisp/pcl.

    I wrote this parser because it makes a full Perl ==> Common Lisp transpiler possible. There’s already a prototype compiler in the repository as well; please see REMAINING.md for details. Moo/Moose would likely need to be handled by mapping them onto Common Lisp’s object system. String evals will have to wait until the transpiler itself is transpiled to CL.

    I think this could be useful. If nothing else, as a way to take the Lisp S-expression output and translate it into other languages. Does this sound worthwhile, or should I be doing something else instead? 🙂

Moo with DBIC
1 direct reply — Read more / Contribute
by Galdor
on Jan 07, 2026 at 04:19
    I prefer Moo to Moose - how can I ensure returned DBIC objects are Moo rather than Moose? How can I tell?
DropBox Delete files
2 direct replies — Read more / Contribute
by frank1
on Dec 26, 2025 at 11:37

    Am trying to delete files uploaded 1 hour below, on Dropbox but am getting this error. even tho i have files uploaded below 1 hour ago

    No files found from the last hour to delete.

    #!/usr/bin/perl use strict; use warnings; use DateTime; use JSON; use WebService::Dropbox; my $Token_id = ''; my $key = ''; my $secret = ''; # Initialize Dropbox client my $dropbox = WebService::Dropbox->new({ key => $key, secret => $secret, }); $dropbox->access_token($Token_id); # Calculate the timestamp from one hour ago my $one_hour_ago = DateTime->now()->subtract(hours => 1); my @files_to_delete; # List files from a specific folder # Use "" for root dir my $result = $dropbox->list_folder({ path => "" }); foreach my $file_metadata (@{ $result->{entries} }) { if ($file_metadata->{'.txt'} eq 'file') { # Parse the file's timestamp my $file_modified_dt = DateTime->from_iso8601($file_metadata-> +{client_modified}); # Check if the file was modified within the last hour if ($file_modified_dt > $one_hour_ago) { push @files_to_delete, $file_metadata->{path_display}; } } } if (@files_to_delete) { # Delete the collected files in a batch $dropbox->delete({ entries => \@files_to_delete }); print "Deleted " . scalar(@files_to_delete) . " files uploaded in +the last hour.\n"; } else { print "No files found from the last hour to delete.\n"; }
Try::Tiny and -E
2 direct replies — Read more / Contribute
by 1nickt
on Dec 26, 2025 at 07:39

    Maybe I ate too much turkey yesterday, but ... using perl 5.40.1, why does this code work:

    $ perl -MTry::Tiny -e 'try {1/0};' $
    while this code gets an error:
    $ perl -MTry::Tiny -E 'try {1/0};' syntax error at -e line 1, near "};" Execution of -e aborted due to compilation errors. $
    Thanks.


    The way forward always starts with a minimal test.

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 pondering the Monastery: (4)
    As of 2026-01-21 09:55 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What's your view on AI coding assistants?





      Results (125 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.