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
System for calculating timing of reminder messages?
4 direct replies — Read more / Contribute
by jest
on Sep 19, 2025 at 10:06

    This is a broad question; I'd be happy to be directed to any package for, or discussion of, this issue, even in Python or other languages.

    I'm working with a legacy system that has functionality for sending reminder emails in relation to various events. It is unbelievably complicated, involving tens of thousands of lines of spaghetti if-else code, using dozens of non-obvious configuration variables. It seems to me that someone must have dealt with this before, and that there's a cleaner solution in place for this not-unusual problem, but I haven't been able to find anything.

    The current system allows for many, many variations: Number of reminders in between "now" and the event; sending reminders every X days from "now"; sending reminders every X days before the event; adjusting the scheduling after a manual event (that is, if you manually cause a reminder to be sent, does that affect the timing of the remaining reminders, and if so, how); changing the timing in between reminders (e.g. the first reminders are a week apart, but the schedule compresses as we draw near to the event); reminders are usually sent by email but can also be sent by other mechanisms, and these don't necessarily work on the same schedule as the emails; etc. etc. etc.

    The system is in use among a large number of people, and apparently many people genuinely do use all of these features at one point or another, so we can't simplify it by removing functionality. But any time we do need to make a change, we end up with even more spaghetti mess, and testing is a nightmare.

    Is there a term for this, or some widely understood way of handling this problem, that I just haven't encountered? Thanks for any suggestions.

remove lending figures
3 direct replies — Read more / Contribute
by frank1
on Sep 18, 2025 at 13:10

    i have a JSON response of this

    0.0  #time dot seconds

    my question is how to get lending figures before (.) dot and have output 0

    same applies to below

    0:00 #time and seconds

    my question is how to get lending figures before (:) dots and have output 0

ExtUtils::MakeMaker, Makefile.PL: modify existing targets like "all" (as in make all) or "install"
2 direct replies — Read more / Contribute
by bliako
on Sep 17, 2025 at 09:48

    Dear Monkees,

    I am using ExtUtils::MakeMaker for all of my projects just because it is how I started. I know how to create custom targets with it using the "postamble". Now I need to modify certain targets like all in order to add more tasks during making. For example, I have need to create special files before compilation, let's call this target translations (because it translates various strings to various languages and provides multilingual strings). This target should be called prior to whatever target all does. How do I achieve this?

    Of course I can add a new target allall as

    allall : translations all
    But since my ability and will to remember special cases diminishes with time, I would prefer to always use standard targets.

    bw, bliako

how to call gtk3::vte::grab_text_range
2 direct replies — Read more / Contribute
by hanspr
on Sep 17, 2025 at 03:50

    Dear Monks

    I'm trying to read a range of text from Vte::Terminal

    There is a very old reference of Gtk2::Vte on how to call this method at :
    https://gtk2-perl.sourceforge.net/doc/pod/Gnome2/Vte/Terminal.html

    And this link documents the function and its parameters
    https://api.gtkd.org/vte.Terminal.Terminal.getTextRange.html

    My problem is that I don't understand how to create the $func parameter

    I have tried this code, but it fails with fatal errors

    $$self{_GUI}{_VTE} = Vte::Terminal->new(); # more code my $func = sub { return 1 }; my $string = $$self{_GUI}{_VTE}->get_text_range($row, $col, $row, $end +_col, $func, my $data = undef);
    ERROR:gperl-i11n-invoke-c.c:584:_allocate_out_mem: assertion failed: (interface_info)
    Bail out! ERROR:gperl-i11n-invoke-c.c:584:_allocate_out_mem: assertion failed: (interface_info)
    

    And many other variants that make even less sense, and all of them fail. Inclusive passing the undef value to the function.

    For example this line does not crash, but it does not work either

    my $func = {sub => {return 1}}; my $string = $$self{_GUI}{_VTE}->get_text_range($row, $col, $row, $end +_col, $func, my $data = undef);

    I need to be able to grab the text from a line where the user clicks, so I can test for the existence of a url and then try to open the url on a browser.

    This is for the open source project asbru on github

    If you need a working code, the only option I can offer is to clone the repo at : https://github.com/asbru-cm/asbru-cm

    Edit PACTerminal.pm and around line 1141 you should see the button_press_event

    In the button_press_event, you can add the line to grab the text with any fixed parameters at any point when the user clicks

    Thanks

CGI::Fast timing out with uploads of large files not small ones
1 direct reply — Read more / Contribute
by mldvx4
on Sep 16, 2025 at 11:55

    Esteemed Monks,

    I have the short script below for receiving files over HTTPS and saving them in a directory. It works great for files of a few hundred kB or less in size. However, for files around 50MB or larger, the script times out without saving the files.

    I've tried increasing the timeout for the HTTP daemon (OpenBSD's httpd) but that shouldn't be needed, the upload should take only a second or so with these network speeds, as with SFTP.

    #!/usr/bin/perl use CGI::Fast; use CGI::Carp qw(fatalsToBrowser); use strict; use warnings; my $socket = '/var/www/run/sockets/upload.sock'; # max file upload size MB $CGI::POST_MAX = 1024 * 1024 * 500; $ENV{FCGI_SOCKET_PATH} = $socket; $ENV{FCGI_SOCKET_PERM} = 0775; while (my $q = CGI::Fast->new) { print qq(Content-Type: text/html; charset=utf-8\n\n); print qq(<!DOCTYPE html>\n); print qq(<html xmlns="http://www.w3.org/1999/xhtml">\n); my $head = &head_default; print qq(<head>\n$head\n</head>\n); my $body; if ( $q->param && $q->request_method() eq 'POST') { $body = &upload($q); } else { $body = &body_default; } print qq(<body>\n$body\n</body>\n); print qq(</html>\n); } exit(0); sub head_default { my $css = &css; my $head = <<"EOH"; <title>Hello, World</title> $css EOH return($head); } sub css { my $css=<<EOC; <style type="text/css" media="screen"> /*<![CDATA[*/ BODY { font-family: sans-serif; margin: 0; } H1 { font-size: 150%; font-weight: bold; font-family: serif; background-color: #a080ff; padding-left: 1em; padding-right: 1em; border-right: thin solid #000000; border-left: thin solid #000000; } P.update { clear: both; font-size: 60%; text-align: center; margin-left: 0.5em; margin-right: 0.5em; } FORM { border: thin solid #000; } FORM > LABEL:has(~ DETAILS[open]) { display: none; } } /*]]>*/ </style> EOC return($css); } sub body_default { my $body; $body .= <<EOB; <h1>Upload a File</h1> <p></p> <form method="post" enctype="multipart/form-data"> Select a file to upload: <input type="file" name="fileToUpload" id="fileToUpload"> <br /> &nbsp; <br /> <input type="submit" value="Upload File" name="submit"> </form> EOB return($body); } sub upload { my ($q) = (@_); if (!$q->param('fileToUpload')) { return(0); } my $file = $q->param('fileToUpload'); $file =~ s/\s+/ /g; $file =~ s/[^\w\ \_\.\-]+//g; if (! $file) { return(0); } my $upload_dir = "/var/www/uploads"; my $upload = $q->upload('fileToUpload'); open ( my $ufile, ">", "$upload_dir/$file" ) or die "$!"; binmode($ufile); while ( my $data = <$upload> ) { print $ufile $data; } close ($ufile); my $body = <<EOB; <p> The file <b>$file</b> was uploaded successfully. <br /> Press the <b>back</b> button or close this tab. </p> EOB return($body); }

    Again, it seems to work fine with smaller files. What should I look at tweaking in order to upload larger files? Any other tips welcome, too.

strip out of single quotes
2 direct replies — Read more / Contribute
by frank1
on Sep 16, 2025 at 09:26

    i have a JSON response of this

    90'+7'

    my question is how to strip out of single quotes between +7 and have integer 90+7 = 97

    i want to strip out of single quotes when time '+additional time' exits, if not then nothing to strip out

parse json
2 direct replies — Read more / Contribute
by frank1
on Sep 14, 2025 at 12:56

    i need some help on parsing some json msg, am doing a get request and getting the json output, but need help in parsing it and separating both teams with thier scores in declosed "competitors": {}, {}

    this is my json output

    { "leagues": [ { "id": "700", "season": { "year": 2025, "type": { "id": "1", "type": 13481 } }, "logos": [ { "width": 500, "height": 500, "rel": [ "full", "default" ], "lastUpdated": "2019-05-08T16:07Z" }, { "width": 500, "height": 500, "rel": [ "full", "dark" ], "lastUpdated": "2021-08-10T20:43Z" } ], "calendarType": "day", "calendar": [ "2025-08-15T07:00Z" ] } ], "events": [ { "id": "740633", "season": { "year": 2025, "type": 13481 }, "competitions": [ { "id": "740633", "status": { "clock": 540, "displayClock": "9'", "period": 1, "type": { "id": "25", "shortDetail": "9'" } }, "venue": { "id": "197", "fullName": "Turf Moor", "address": { "country": "England" } }, "format": { "regulation": { "periods": 2 } }, "notes": [], "geoBroadcasts": [], "broadcasts": [], "broadcast": "", "competitors": [ { "id": "379", "homeAway": "home", "score": "0", "records": [ { "name": "All Splits" } ], "team": { "id": "379", "name": "Burnley", "links": [ { "rel": [ "clubhouse" ], "isHidden": false }, { "rel": [ "stats" ], "isHidden": false }, { "rel": [ "schedule" ], "isHidden": false }, { "rel": [ "squad" ], "isHidden": false } ], "venue": { "id": "197" } }, "statistics": [ { "name": "appearances" } ] }, { "id": "364", "homeAway": "away", "score": "0", "records": [ { "name": "All Splits" } ], "team": { "id": "364", "name": "Liverpool", "links": [ { "rel": [ "clubhouse" ], "isHidden": false }, { "rel": [ "stats" ], "isHidden": false }, { "rel": [ "schedule" ], "isHidden": false }, { "rel": [ "squad" ], "isHidden": false } ], "venue": { "id": "192" } }, "statistics": [ { "name": "appearances" } ] } ], "details": [], "odds": [ { "provider": { "id": "2000" }, "awayTeamOdds": { "summary": "1/3", "team": { "id": "364" }, "link": { "language": "en-GB", "rel": [ "away" ], "isHidden": false } }, "homeTeamOdds": { "summary": "8/1", "team": { "id": "379" }, "link": { "language": "en-GB", "rel": [ "home" ], "isHidden": false } }, "drawOdds": { "summary": "4/1", "link": { "language": "en-GB", "rel": [ "draw" ], "isHidden": false } } } ], "wasSuspended": false, "playByPlayAvailable": true, "playByPlayAthletes": true } ], "status": { "clock": 540, "displayClock": "9'", "period": 1, "type": { "id": "25", "shortDetail": "9'" } }, "venue": { "displayName": "Turf Moor" }, "links": [ { "language": "en-GB", "rel": [ "live" ], "isHidden": false }, { "language": "en-GB", "rel": [ "stats" ], "isHidden": false } ] } ] }

    this is my part of script i want to fix, and output all teams with the scores

    for my $match (@{$parse_json->{leagues}}) { my $elapsed = $match->{competitions}{status}{displayClock}; my $status = $match->{wasSuspended}; my $home = $match->{competitors}{team}{homeAway}; my $away = $match->{competitors}{team}{homeAway}; my $away_goal = $match->{competitors}{score}; my $home_goal = $match->{competitors}{score}; print "$elapsed: $home: $home_goal: Suspended Match: $status"; print "$elapsed: $away: $away_goal: Suspended Match: $status"; }
Type::Params signature_for - can it handle method + variable string args without arrayref wrapping?
1 direct reply — Read more / Contribute
by Anonymous Monk
on Sep 13, 2025 at 11:14

    I'm trying to create a signature_for an import method that should be called like:

    MyPackage->import(qw(symbol1 symbol2 symbol3));

    I need to validate that: It's a proper method call (class name first) Followed by at least one non-empty string argument But I want the arguments to remain as individual scalars in @_, not get wrapped into an arrayref. Every approach I've tried with slurpy ends up forcing the string arguments into an arrayref:

    use Type::Params qw( signature_for ); use Types::Standard qw( slurpy Any ); signature_for import => ( method => 1, pos => [ slurpy Any ], ); sub import { warn "Args: ", join(", ", map { ref($_) || $_ } @_), "\n"; # Shows: Args: MyPackage, ARRAY(0x...) }

    Is there a way to make signature_for validate the method signature but leave the variable argument list as individual scalars in @_? Or is Type::Params fundamentally designed around restructuring arguments into containers?

    Currently using Params::Validate which works fine, but curious if Type::Params can handle this use case.

Retrieve and Print TextArea Content
1 direct reply — Read more / Contribute
by Milti
on Sep 12, 2025 at 11:06

    I want to retrieve and print the contents of a Text Area exactly as it was input from a keyboard, i.e. with no HTML formatting. I am using the code noted below. The content is retrieved and printed but as a single line when it was entered as multiple paragraphs. This is the code I am using

    use strict; use warnings; use CGI; my $q = CGI->new; # Print the HTTP header print $q->header; # Get the content of the text area. # Replace 'textarea_name' with the actual 'name' attribute of your HTM +L textarea. my $textarea_content = $q->param('message'); # Print the content exactly as received ####print "Content of the text area:\n"; print $textarea_content;

    When content is entered as HTML it is returned as originally entered. Otherwise the return is one line. Is there a way to solve my problem? Thanks for any and all help!

Label makes a sub to return empty list -- "secret"? documented?
1 direct reply — Read more / Contribute
by Anonymous Monk
on Sep 11, 2025 at 05:58

    (Assuming the PM is sooner alive than dead & I can still read/write here), I noticed some cpan modules have a label (the _: to be specific, mostly in modules by SPROUT, but also perl itself if example is needed) at the end of a sub; it's deparsed into () i.e. empty list. Why? Is this behaviour documented anywhere?


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.