how portable is the random number generator?
5 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.
|
Dropbox problem
2 direct replies — Read more / Contribute
|
by frank1
on Dec 24, 2025 at 09:55
|
|
|
i have a problem of uploading files to Dropbox, this is the error i get
[WebService::Dropbox] [ERROR] https://content.dropboxapi.com/2/files/u
+pload {"path":"/Uploads/$filename"} -> [400] Error in call to API fun
+ction "files/upload": Must provide HTTP header "Authorization" or URL
+ parameter "authorization". at WebService/Dropbox.pm line 184.
My full code
#!/usr/bin/perl
use lib '.';
use strict;
use warnings;
use WebService::Dropbox;
use IO::File;
my $filename = '/var/www/vhosts/path/httpdocs/path/file.txt';
my $access_token = '';
my $dropbox = WebService::Dropbox->new({
key => $access_token,
# oauth2 is true by default for recent versions
});
my $local_file = $filename;
my $remote_path = '/Uploads/$filename';
my $content = IO::File->new($local_file, '<') or die "Cannot open $loc
+al_file: $!";
my $result = $dropbox->upload($remote_path, $content);
if ($result) {
print "Successfully uploaded $local_file to Dropbox as $remote_pat
+h\n";
} else {
die "Upload failed: " . $dropbox->error;
}
|
GD module has no support for animated gifs
7 direct replies — Read more / Contribute
|
by Anonymous Monk
on Dec 22, 2025 at 23:59
|
|
|
Hello perlmonks. I am hosting a website and for that purpose i want to make some animated gifs. I have downloaded the module GD but it gives the following error: libgd 2.0.33 or higher required for animated GIF support at C:\gd.pl line 7. I downloaded it again to make sure i have the right version, and i get the following message: GD is up to date. (2.83). It seems to me i have the right version but i am relatively new to perl. I have been looking on the internet but am unable to find an answer, therefore i seek your help. If you cannot help me i will have to find some other way to make some animated gifs. Thank you.
|