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
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.

S-expressions with Marpa::R2: Grammar for Numbers
2 direct replies — Read more / Contribute
by karlgoethebier
on Dec 22, 2025 at 07:28

    I use this to process s-expressions with Marpa::R2:

    my $DSL = <<'DSL'; :default ::= action => ::first lexeme default = latm => 1 start ::= sexp sexp ::= list | atom list ::= LPAREN elements RPAREN action => Sexp::Tiny::Actions::do_list elements ::= element* action => Sexp::Tiny::Actions::do_elements element ::= sexp atom ::= string | symbol string ::= DQUOTE string_chars DQUOTE action => Sexp::Tiny::Actions::d +o_string | DQUOTE DQUOTE action => Sexp::Tiny::Actions::do_ +empty_string string_chars ::= string_char+ action => Sexp::Tiny::Actions::do_join string_char ::= STRCHAR DQUOTE ~ '"' STRCHAR ~ [^"] symbol ::= symbol_chars action => Sexp::Tiny::Actions::do_symbol symbol_chars ::= symbol_char+ action => Sexp::Tiny::Actions::do_join symbol_char ::= SYMCHAR SYMCHAR ~ [^()\s"] LPAREN ~ '(' RPAREN ~ ')' :discard ~ WS WS ~ [\s]+ DSL

    Probably awkward and there are certainly better ways, but it works: (i skip the processing part):

    karl@pazuzu:~/src/perl/debug/sexp-tiny$ bin/sexp.pl examples/fossil.da +t { fields => { "anonymous" => "off", "canonical-url" => "https://goethebier.space/fossi +l/p-acme", "crlf-glob" => "*.bat *.cmd", "crnl-glob" => "", "default-user" => "karl", "hash-policy" => "sha3", "http-port +" => 8081, "ignore-glob" => ["*.o", "*.swp", "*.tmp", ".dir +env/", "_build/", "_opam/"], "localauth" => "on", "max-upload" => "20MB", "project-d +escription" => "Private ACME tooling repository", "project-name" => "p-acme", "ssl-ca-location" => "/etc/ssl/certs", "throttle" => 0, "timeline-utc" => "on", }, type => "fossil", }

    But it only works for strings so far:

    karl@pazuzu:~/src/perl/debug/sexp-tiny$ echo '(acme (foo "bar"))' | bin/sexp.pl { fields => { foo => "bar" }, type => "acme" }

    But not with numbers:

    karl@pazuzu:~/src/perl/debug/sexp-tiny$ echo '(acme (x 1))' | bin/sexp +.pl bin/sexp.pl expected (key value...)

    I can only pass them in as string:

    karl@pazuzu:~/src/perl/debug/sexp-tiny$ echo '(acme (x "1"))' | bin/se +xp.pl { fields => { x => 1 }, type => "acme" }

    How must i modify the grammar to handle numbers (float and int)? I didn't find an example yet.

    Update:

    I'll try to illustrate how i did it:

    #!/usr/bin/env perl use strict; use warnings; use lib 'lib'; use Sexp::Tiny::Grammar (); use Data::Dump qw(dd); use Scalar::Util qw(blessed); my $src = q{(acme (pi "3.14")(nose "cuke"))}; dd $src; my $r = Sexp::Tiny::Grammar::build_reader(); dd ref($r); $r->read( \$src ); my $ast_ref = $r->value; dd $ast_ref; sub is_qstr { my ($v) = @_; return blessed($v) && $v->isa('Sexp::Tiny::String'); } sub unwrap_qstr { my ( $v, $path ) = @_; if ( is_qstr($v) ) { warn "[unwrap] $path: ", ref($v), qq{ -> plain perl string "}, $v->value, qq{"\n}; return $v->value; } return $v; } sub maybe_number { my ( $v, $path ) = @_; return $v if ref $v; if ( defined($v) && $v =~ /\A[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?\z/ ) { warn "[numify] $path: \"$v\" -> ", 0 + $v, "\n"; return 0 + $v; } return $v; } sub normalize { my ( $node, $path ) = @_; $node = unwrap_qstr( $node, $path ); if ( ref($node) eq 'ARRAY' ) { my @out; for my $i ( 0 .. $#$node ) { push @out, normalize( $node->[$i], "$path\[$i\]" ); } return \@out; } return maybe_number( $node, $path ); } my $norm = normalize( $$ast_ref, '$ast' ); dd $norm;

    Looks like it's doing what it's supposed to do:

    karl@pazuzu:~/src/perl/sexp-tiny$ leftovers/ex02.pl "(acme (pi \"3.14\")(nose \"cuke\"))" "Sexp::Tiny::Grammar::Reader" \[ "acme", ["pi", bless(do{\(my $o = 3.14)}, "Sexp::Tiny::String")], ["nose", bless(do{\(my $o = "cuke")}, "Sexp::Tiny::String")], ] [unwrap] $ast[1][1]: Sexp::Tiny::String -> plain perl string "3.14" [numify] $ast[1][1]: "3.14" -> 3.14 [unwrap] $ast[2][1]: Sexp::Tiny::String -> plain perl string "cuke" ["acme", ["pi", 3.14], ["nose", "cuke"]]

    my $src = q{(acme (pi 3.14)(nose "cuke"))}; works as well.

socket programming
2 direct replies — Read more / Contribute
by Anonymous Monk
on Dec 20, 2025 at 12:25

    I am doing a little bit of networking and i am trying to write a script that lets me communicate with servers. I was wondering if it's a good idea to use the module Net::Telnet instaed of working with sockets. If working with sockets directly is the way to go forward is it useful/better to use the built-in socket functions iso using the module IO::Socket::INET, or maybe it is more or less the same? I hope to hear from you, ty.

Passing a hash plus some strings to a subroutine
4 direct replies — Read more / Contribute
by mldvx4
on Dec 17, 2025 at 09:52

    What is the correct way to pass a hash to a subroutine separately from a few strings? I have been using the following method,

    sub generate { my $record = shift; my $status = shift; my %data = %{$_[0]}; ...

    However, that brings up an "Always unpack @_ first" error with perlcritic --stern and therefore I wonder if there is a more appropriate method.

mtlsproxy feedback
1 direct reply — Read more / Contribute
by linuxlegends
on Dec 16, 2025 at 18:01

    I have this perl code this uses App::Spec and HTTP::Proxy to act as a forward proxy that handles mTLS requests - https://gitlab.com/infrastructure24/mitmtls/-/blob/main/src/mtlsproxy.sh?ref_type=heads. I'm planning on converting it to a CPAN module named App::Mtlsproxy since I was not able to find anything in CPAN that performs this task with a good CLI interface. The PAUSE documentation recommends posting here before uploading to get feedback. Does this seem like a good thing to upload to CPAN?

getting headers from essage
4 direct replies — Read more / Contribute
by Anonymous Monk
on Dec 16, 2025 at 14:25

    I am trying to get some headers from an email message using an imap module but it is getting complicated. I am trying to work with a hash reference in which the keys are the header field names and the values are references to arrays of values. This is what the documentation says. I managed to capture those headers in arrays, but there is always only one element where all the info is stored. It does not matter with 'From' or 'Subject', but with 'To' it is unwanted because there is often more then one of those.So iam trying to get to this array of arrays element I solved it with splitting the string and removing leading and trailing spaces, but it's not fantastic. Could someone have a look at my script and give me some advice on how to proceed? I'll show you what i got so far:

    use strict; use warnings; use Mail::IMAPClient; my $imap = Mail::IMAPClient->new( Server => 'imap.gmail.com', User => 'jim@gmail.com', Password => '*******', Ssl => 1, Debug => 0, ); die "failed to instantiate $@." unless defined $imap; $imap->select('INBOX'); my $msgcount = $imap->message_count(); print "$msgcount number of measages in your mailbox\n\n"; my @messages = $imap->messages; pop(@messages); my $msgid = pop(@messages); my $text = $imap->bodypart_string($msgid,1); my $hashref = $imap->parse_headers( $msgid, "Subject","To","From"); my @sender = @{%$hashref{"From"}}; my @recs = @{%$hashref{"To"}}; my @subject = @{%$hashref{"Subject"}}; my @rec = split(/,/, $recs[0]); print "From: $sender[0]\n"; print "Subject: $subject[0]\n\n"; foreach(@rec){ $_=~ s/^\s+|\s+$//g; print "To: $_\n"; } print $text; $imap->logout();

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.