Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

The Monastery Gates

( #131=superdoc: print w/replies, xml ) Need Help??

If you're new here please read PerlMonks FAQ
and Create a new user.

poll ideas quest 2021
Starts at: Jan 01, 2021 at 00:00
Ends at: Dec 31, 2021 at 23:59
Current Status: Active
0 replies by pollsters
    First, read How do I create a Poll?. Then suggest your poll here. Complete ideas are more likely to be used.

    Note that links may be used in choices but not in the title.

Perl News
What is your favourite Linux scripting or programming language?
on Jan 25, 2021 at 09:33
4 replies by choroba
    You can vote on the RedHat poll here.

    When I voted, Perl was #3!

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Coding in Perl? What support do you need?
on Jan 06, 2021 at 05:15
7 replies by marto

    Coding in Perl? What support do you need? over at the Perl foundation website has a linked survey:

    "But think about this. If we switched Perl off today, there would be a problem. A huge problem! We know that Perl is the glue that holds a lot of the IT world together. The Perl Foundation wants to support the community to make sure that the IT world doesn’t fall apart and supporting people learning Perl is a big element of that.

    We have developed a survey that needs just a few minutes of your time, to tell us what you would like, or need, to support your move into, or progress within, the Perl language."

What defines the output format of a Postgres Timestamp
4 direct replies — Read more / Contribute
by Skeeve
on Jan 26, 2021 at 01:41

    I'm using Mojolicious and Mojo::Pg to create an API.

    When retrieving a timestamp from the database, without converting the timestamp TO_CHAR, I get something like this:

    { "created" => "2020-09-22 10:16:39.307719+02" }

    Now I'm wondering where the output format is defined.

    As I would always require all timestamps to be in a RFC3339 format, I would have to change each and every select statement to have a TO_CHAR with the proper format.

    There must be a more practical way of defining the format for all timestamps at a central place, but i have no clue where.

    One of the answers on Stackoverflow suggests that

    The display is completely controlled by the SQL client, not by the server.

    The SQL client here should be DBD::Pg.

    But maybe that's the wrong place to search and the conversion of a timestamp to a string representation is done at a later stage e.g. when doing the encode_json?

    My current attempts in finding the spot where to change the format were fruitless :(

    I hope someone here can give me more ideas where to search.

CPAN namespace hierarchy
5 direct replies — Read more / Contribute
by GrandFather
on Jan 24, 2021 at 16:29

    Is there a way to browse the CPAN namespace hierarchy? I'm trying to figure out the best place to fit a new module for parsing and dumping selected contents of ELF files. I've scanned through the PAUSE docs that looked most likely to lead the way, but didn't see anything.

    Hmm, while preparing this question I found which is at least part of the answer, but somewhat unwieldy. Maybe I'll just have to put a Tk wrapper around that data unless someone has a suitably lazier option for me?

    Update: https://ELF::Extract::Sections exists already and has a name rather like what I would want to use. However it's dependency heavy and has a pretty bad rep on cpantesters, especially for Windows builds. I did try installing ELF::Extract::Sections, but after a rather long time it failed as might have been guessed from the testers reports. I'm open to suggestions for an alternate name in the vicinity of the ELF::Extract name space.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
Critique requested for module code - QuickMemo+ reader
5 direct replies — Read more / Contribute
by Lotus1
on Jan 24, 2021 at 12:47

    While I'm still thinking over the excellent suggestions I received for the name for the module here is the code. Please help with suggestions or critiques.

    The module extracts the memo text from the lqm files that QuickMemo+ exports. The lqm file is actually a zip file that contains a JSON file that contains the memo text so it was an easy module to write. Each memo is in a separate archive so it is very tedious to extract each memo by hand.

    Update: I neglected to add my tests as Discipulus wisely pointed out. Since I have prove -l working now with my tests I have been enjoying refactoring and letting the tests help me find the errors.

Executing program with arguments from cgi script
2 direct replies — Read more / Contribute
by natol44
on Jan 24, 2021 at 12:27

    I need to run ffmpeg from a CGI script, of course with arguments: Video to process, watermark to add, etc, and output file.

    I put all this in one variable:

    my $order = "$ffmpeg -i $video -i $watermark parameters etc $output";

    with $ffmpeg is the program's address, $video the video address etc.

    then I tried with

    system "$order";

    Nothing works.

    If I write the output content of $order in the SSH command line, it works.

    Where am I wrong? Thank you!
Ordering Template cards
5 direct replies — Read more / Contribute
by Bod
on Jan 24, 2021 at 11:03

    An internal system for business displays a series of 'cards' which show key data across various parts of the business all in one place. These are quite diverse and cover things like property occupancy levels, future pricing data and call centre call volume.

    Currently this is implemented with a bespoke kind of template. There is an HTML file with placeholders for all the data items and a Perl script which gathers all the data from various systems across the business, reads the file, substitutes that data into the placeholders before displaying the output. It can be viewed at any time as a webpage but also runs twice per week from CRON and sends an email to key people. The script knows the difference by checking if $ENV{'GATEWAY_INTERFACE'} is defined.

    This system already has 106 placeholders and needs extra information adding to it and I've decided to take the opportunity to refactor it to use Template thanks to the good influence of the Monastery! As part of the refactoring I want to add the facility for different users to be able to view the system with the cards in an order to suit them. Perhaps even to be able to hide the ones that do not interest them. We operate an open information policy so everyone in the business is permitted to see everything so there are no permission issues but not everything is actually useful to everyone so it would be good if they could put the cards they use most at the top and ones they seldom use further down.

    In trying to work out how to implement this I have come up with a solution but it seems there must be a more elegant solution.

    I've considered having a database table consisting of 4 fields:

     - User_idUser      - Foriegn Key to primary of User table
     - Card_idCard      - Foreign Key to primary of Card table
     - metric           - order to display cards for user
     - visible          - boolean - show card to user?
    with User_idUser and Card_idCard being the composite primary key.

    Then have a Perl script (of course!) that reads the cards from the database in the order given by metric. For each card it calls a subroutine that assembles the appropriate data for that card and uses Template to display the template file for that card. There will need to be 12 template files plus one for header and footers. Something like this (untested):

    my $cards = $dbh->prepare("SELECT Card_idCard FROM CardList WHERE User +_idUser = $user_number AND visible = 1 ORDER BY metric"); $cards->execute(); while (my $card = $cards->fetchrow_array) { card_call_center() if $card == 1; card_price_data() if $card == 2; card_occupancy() if $card == 3; # etc etc } # ... sub card_call_center { # Collect data # from systems my $vars = { 'foo' => bar, 'some' => data, }; $template->process('', $vars); }
    But I especially do not like the conditional subroutine calls with magic numbers in the statement modifiers.

    Is there a more elegant solution?
    Should I be calling multiple template files from the script or should that processing be done within Template?

guidance on naming my first module for CPAN
6 direct replies — Read more / Contribute
by Lotus1
on Jan 23, 2021 at 17:05

    I'm looking for guidance on naming my first module for CPAN. So far I've been calling it


    The purpose of the module is to help me extract the large number of memos I have written on my LG smartphone in QuickMemo+. The module extracts the memo text from the lqm files that QuickMemo+ exports. I couldn't find any software that could open those files other than 7zip. The lqm file is actually a zip file that contains a JSON file that contains the memo text so it was an easy module to write. Each memo is in a separate archive so it is very tedious to extract each memo by hand.

    My questions are:

    • Is this name acceptable for CPAN? Some other options I considered are:
      • LG::QuickMemo_Plus::Memo::Extract
      • LG::QuickMemo+::Memo::Extract
      • QuickMemo_Plus::Memo::Extract
      • QuickMemo_Plus::Extract::Memo
      • QuickMemo_Plus::Extract
    • Is a module like this needed on CPAN?
      • I'm thinking it might be better to just make a small GUI and release the binary on Github. My plan is to do both. But I wonder how many Perl programmers would be interested in this module.
.dancer -- what's it for
2 direct replies — Read more / Contribute
by kcott
on Jan 22, 2021 at 11:28

    G'day All,

    I keep seeing the file '.dancer' when working with Dancer2. It's in every tutorial but never explained. I've no idea what this file is for.

    Any ideas?

    — Ken

Unpacking byte stream long/quad little/big endian fields
3 direct replies — Read more / Contribute
by GrandFather
on Jan 21, 2021 at 19:54

    I have a binary file (think ELF or Windows PE) that includes fields that may be long (32 bit) or quad (64) bit and little or big endien depending on the specific file. The script may be running on a big or little endian machine with a Perl built for 32 or 64 bits. I want to unpack the fields for later use that will include display using printf and file operations using read and seek so I need to convert from file representation to the running Perl's native representation for those fields. The following sample code does that, but the pack 'L2' ...; unpack 'Q' feels a bit clunky. Can it be tidied up?

    use warnings; use strict; use Config; use Fcntl; printf "Perl $^V %s ivsize %d byteorder %d\n", $Config{archname}, $Config{ivsize}, $Config{byteorder}; # Generate a "binary file" with a string of bytes likely to show up is +sues in # decoding my $binary = "\x91\x34\x33\x90\x81\x32\x31\x80"; for my $fileLE (0, 1) { my $fromFile = $fileLE ? 'V4' : 'N4'; open my $inFH, '<:raw', \$binary; read $inFH, my $raw1, 4; read $inFH, my $raw2, 4; my $long1 = unpack $fromFile, $raw1; my $long2 = unpack $fromFile, $raw2; my $packed = pack "L2", $fileLE ? ($long1, $long2) : ($long2, $lon +g1); my $longlong = unpack 'Q', $packed; printf "%s: %016x\n", ($fileLE ? "LE" : "BE"), $longlong; }

    A 32 bit Windows build prints:

    Perl v5.32.0 MSWin32-x86-multi-thread-64int ivsize 8 byteorder 1234567 +8 BE: 9134339081323180 LE: 8031328190333491

    A nice sanity check would be to run the code on a big endian system and see that the numbers generated are the same. Of course the long long processing will come unstuck where ivsize < 8.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
perl script to conda package
1 direct reply — Read more / Contribute
by jnarayan81
on Jan 21, 2021 at 11:51
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2021-01-27 11:26 GMT
Find Nodes?
    Voting Booth?