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
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
6 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
3 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();
ORM for new native Perl Object System
3 direct replies — Read more / Contribute
by Galdor
on Dec 16, 2025 at 02:39

    Evaluating new Perl v5.38 OOP class keyword. Seems very promising.

    However I cannot really use it for any serious applications without some kind of ORM (like DBIx::Class?) ) to persist data in standard Pg/SQLite databases - what are my options if any?

    The ability to "reverse Enginner" the DB schema into class file would be key due to fairly extensive DB schemas.

    BTW - by what name do I refer to this object system to differentiate from the hundreds of other Perl object systems?

send mail with STARTTLS
4 direct replies — Read more / Contribute
by Anonymous Monk
on Dec 15, 2025 at 00:57

    Hi i am trying to write an email with my gmx mail account. It requires STARTTLS or TLS. I need to find out some things before i can do this but i first have a question about the difference between the modules Net::SMTP and Net::SMTPS, because it looks like both can do the job. The modules came automattically with my download of strawberry perl. Could someone tell me the difference between them? I have already tried to use the module Net::SMTP::TLS but i got an error on the SSL version and i have heard that it is an outdated module. Any advice is welcome. Ty.

prove can't find my module, even though its directory is in $INC[0] (Solved)
7 direct replies — Read more / Contribute
by HenryLaw
on Dec 14, 2025 at 17:57

    I'm running tests which are in a ./t subdirectory. Tests are failing with "Can't locate so-and-so in @INC", despite the fact that the missing module is in the first directory named in the dump of @INC. I have $PERL5LIB set. Thus:

    # echo $PERL5LIB /home/henry/gitr/MAS/lib # prove ./t/8bit.t ./t/8bit.t .. Can't locate MAS::Global in @INC (@INC entries checked: +/home/henry/gitr/MAS/lib /etc/perl (... others omitted) # find /home/henry/gitr/MAS/lib -name Global.pm /home/henry/gitr/MAS/lib/MAS/Global.pm # It's in $INC[0] # perl -c /home/henry/gitr/MAS/lib/MAS/Global.pm /home/henry/gitr/MAS/lib/MAS/Global.pm syntax OK

    Perl itself can find it:

    # perldoc -l MAS::Global /home/henry/gitr/MAS/lib/MAS/Global.pm

    Compiler and OS details

    # perl -v This is perl 5, version 38, subversion 2 (v5.38.2) built for x86_64-li +nux-gnu-thread-multi (with 51 registered patches, see perl -V for more detail) # cat /etc/os-release NAME="Linux Mint" VERSION="22.2 (Zara)" ID=linuxmint ID_LIKE="ubuntu debian" ... etc

    I'm fairly sure there's a sensible explanation for this baffling behaviour: would someone either diagnose my error, or suggest some way by which I can home in on what it is?


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.