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.
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.
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)
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
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 -
I've got 1573 CPAN modules and perlbrew clone-modules to 5.42.0 fails to install 57. From 2021 github.com/gugod/App-perlbrew/issues/722 has some ideas on why this happens but I guess it's still broken. Here's the list of failures if someone wants to figure out what these distributions have in common that breaks perlbrew:
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);
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? 🙂
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";
}