Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

The Monastery Gates

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

Donations gladly accepted

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

poll ideas quest 2020
Starts at: Jan 01, 2020 at 00:00
Ends at: Dec 31, 2020 at 23:59
Current Status: Active
9 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
Announcing Perl 7
on Jun 24, 2020 at 15:14
18 replies by marto
Reminder: The Perl and Raku Conference in the Cloud - this week!
on Jun 22, 2020 at 04:36
2 replies by haukex
Ternary Quizical behaviour?
7 direct replies — Read more / Contribute
by bliako
on Jul 10, 2020 at 07:35

    I have a possibly bad habit to compact boring parts of my code like this:

    if( exists($hash->{akey}) && defined($m=$hash->{akey}) && ($m==1) ){ $ +y = $m; ... } # don't trust $m here

    But in this case it has unexpected results. This is the 1st part where a hash is constructed based on whether a key in another hash exists:

    use strict; use warnings; use Data::Dumper; my %tests = ( 'a' => 10, 'b' => 20, ); my $m; # this seems to assign $m once and never bother to check again my %hash = ( 'b' => exists($tests{'b'}) && defined($m=$tests{'b'}) ? $m : 0, 'a' => exists($tests{'b'}) && defined($m=$tests{'a'}) ? $m : 0, ); print Dumper(\%hash); # this works as expected $m = 10; my %hash2 = ( '1' => $m++, '2' => $m++, '3' => $m++ ); print Dumper(\%hash2);
    $VAR1 = { 'a' => 10, 'b' => 10 }; $VAR1 = { '1' => 10, '2' => 11, '3' => 12 };

    Does anyone have an explanation? And is my habit bad?

Perl::Critic says don't modify $_ in list functions and other things
9 direct replies — Read more / Contribute
by Lady_Aleena
on Jul 08, 2020 at 21:29

    Hello all. I have been playing around with Per::Critic on the command line and found to my dismay that some of my modules do not pass gentle. I realize that I can ignore the recommendations of Perl critic, but I would love for my modules to pass "gentle" before I begin ignoring things.

    The most common issue is that I modify $_ in list functions. The following is a convenient and short one liner to put the lines of files into a list. I thought doing it this way was nice and slim.

    my @list = map { chomp($_); $_ } <$fh>; my @uc_list = map { chomp $_; [uc $_] } <$lc_fh>; # used only onc +e my @split_list = map { chomp $_; [ split(/\|/, $_) ] } <$piped_fh>; +# used only once

    In one subroutine, I have this three times.

    Also, my idify subroutine is just modifying $_.

    And my Fancy::Map modifies $_ too.

    If this is something ignored usually, I will ignore it, but I would like to know how to make it better. Should I just assign $_ to a variable and then use the variable?

    Another thing that I am confused by is why the expression form of eval is discouraged?

    The rest of the gentle issues are me being lazy with conditionals. While writing I was thinking my $var = "foo" if 'some condition', but Perl critic does not like it, but it is fixed easily.

    NOTE: Please see my update. Most are fixed, but the eval problem remains.

    My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.8.8 on web host.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Why eval $version?
3 direct replies — Read more / Contribute
by Aldebaran
on Jul 08, 2020 at 18:22

    I'm still processing what I experienced at TPC. I've had time to catch up on some of the youtube videos from the ones I missed. Sometime in all the zooming, I thought I heard one of the presenters say

    that's why we eval version

    I thought it was Sawyer X, who says a lot of things parenthetically, but I went over his talk for a third time and didn't hear it again. I didn't understand what he meant, so I could well have misheard it or just dreamed up the recollection wholesale.

    A couple days later, I'm going through the guts of a test script for local::lib and I see this, beginning line 16 of xt/bootstrap.t

    sub check_version { my ($perl, $module) = @_; my @inc = `$perl -le "print for \@INC"`; chomp @inc; (my $file = "$") =~ s{::}{/}g; ($file) = grep -e, map { "$_/$file" } @inc; return undef unless $file; my $version = MM->parse_version($file); eval $version; }

    Q1) What purpose does this line serve?

     eval $version;

    Q2) Is this a "string eval?"

    Q3) Do dangers lurk in its use, cf. Uri Guttman's 2019 TPC talk on 'eval'?

    Q4) Does anyone else remember the "that's why we eval version" comment, or is it just me?

    Thanks for your comment,

Detect boundaries within .png's - and cropping
6 direct replies — Read more / Contribute
by Stickybit
on Jul 08, 2020 at 02:30

    Hi everyone

    Got at specific problem, that I need some hints on. :-)

    I got a bunch of fixed size .png images with logos. Those logos are centered on the images, and empty space on the left/right of the logo, is transparent background. I need to crop those images on the fly, so that empty space on the left/right of the logo is removed.

    Any hints on how to solve that one? :-)

REST::Client + Request Body
2 direct replies — Read more / Contribute
by ravigupta1
on Jul 07, 2020 at 07:23

    I am trying to connect Quest Foglight using REST::Client over https. I tried in PostMan tool and it is working over there but it accept authToken in Request Body.

    Appreciate if someone could help me to understand how to pass "authToken" in PERL code as Request Body. Below is my code FYR. This is not working as I am new to PERL and don't know how to pass authToken as request body.

    Use REST::Client; my $client = REST::Client->new(); $req = '{"authToken":"<My Auth Token Value>"}'; # Above value should be passed as request Body. As per Postman Tool. $url = "https://<my Quest Server>/api/v1/security/login"; $client->POST($url,$req); print($client->responseCode()); exit();
Perl and MongoDB
3 direct replies — Read more / Contribute
by Theodore
on Jul 06, 2020 at 09:21
    As the MongoDB module will soon be EOL, what the Monastery wisdom says about using MongoDB from Perl?

    I inherited an in-house (rather critical and very well written) Perl application which uses MongoDB as a back end. Replacing this application with another one is not an option for now.

    Should I start looking for another DB to completely replace MongoDB (which is a rather daunting task)? If yes, any suggestions?

    Should i try to keep the application working using the last version (2.2.0) of the driver?

    Any other suggestions?

LWP::UserAgent Alternatives for API data
4 direct replies — Read more / Contribute
by johnfl68
on Jul 05, 2020 at 15:14

    Hello, and as always thank you for help and support.

    I have been using LWP::UserAgent with the NWS API using mirror to save API data for several locations once an hour.

    Lately the API has been having issues (many other people having issues as well, not just me), but I think part of the issues I am having has to do with me using mirror, and occasionally I will get an older data file from NWS, but it will put a future date for the file date for some reason (July 27, 2020 for example), and then it does not update anymore because the file on the server is newer (but old data).

    I am supposed to send User Agent with API requests to NWS. I could go back to just doing GetStore, but don't want to have to change to a UserAgent solution again at some point in the future if I get blocked for not sending it.

    I have looked around and there are dozens of different ways to get and store a file from http, but some may be better suited for this case then others. So before I recode this to do some other get store type option instead of doing a mirror type option (I don't really need to check if I already have the same data at this point), are there any other ways/modules that you would recommend? I am not getting webpages, just JSON and XML data sets.</o>

    Stick with LWP::UserAgent and use 'get' and then just output the response to a file? HTTP::Tiny? Mechanize? Something completely different?

    Thank you!

Best GUI for Perl?
8 direct replies — Read more / Contribute
by geertvc
on Jul 05, 2020 at 09:29
    Hi all,

    I know this is a question that has been asked maybe a zillion times or more but still I want to take the risk asking it again.

    What's the best environment to create GUI's in Perl?

    Perl is maybe not the best language to create GUI's but since I am knowledgeable about wxWidgets, my first choice would be wxPerl. I know this is a bit biased and this question is very subjective (you hardly can't discuss about flavours and tastes, can you?) but my problem is that I can't install wxPerl on my Windows 10 PC where I installed Strawberry Perl. It fails when it wants to compile the Alien::wxWidgets module. This is what I get:

    C:\Users\Geert>cpan -i Wx Loading internal logger. Log::Log4perl recommended for better logging CPAN: CPAN::SQLite loaded ok (v0.217) Database was generated on Sun, 05 Jul 2020 13:15:41 GMT Running install for module 'Wx' CPAN: Digest::SHA loaded ok (v6.02) CPAN: Compress::Zlib loaded ok (v2.093) Checksum for D:\WinApps\PROGRA~1\STRAWB~1\cpan\sources\authors\id\M\MD +\MDOOTSON\Wx-0.9932.tar.gz ok CPAN: Archive::Tar loaded ok (v2.36) CPAN: YAML::XS loaded ok (v0.81) CPAN: CPAN::Meta::Requirements loaded ok (v2.140) CPAN: Parse::CPAN::Meta loaded ok (v2.150010) CPAN: CPAN::Meta loaded ok (v2.150010) ---- Unsatisfied dependencies detected during ---- ---- MDOOTSON/Wx-0.9932.tar.gz ---- Alien::wxWidgets [build_requires] Running install for module 'Alien::wxWidgets' Checksum for D:\WinApps\PROGRA~1\STRAWB~1\cpan\sources\authors\id\M\MD +\MDOOTSON\Alien-wxWidgets-0.69.tar.gz ok CPAN: Module::CoreList loaded ok (v5.20200314) CPAN: Module::Build loaded ok (v0.4231) Configuring M/MD/MDOOTSON/Alien-wxWidgets-0.69.tar.gz with Build.PL Created MYMETA.yml and MYMETA.json Creating new 'Build' script for 'Alien-wxWidgets' version '0.69' MDOOTSON/Alien-wxWidgets-0.69.tar.gz D:\WinApps\Programming\StrawberryPerl\perl\bin\perl.exe Build.PL -- +OK Running Build for M/MD/MDOOTSON/Alien-wxWidgets-0.69.tar.gz Building Alien-wxWidgets process_begin: CreateProcess(NULL, D:/WinApps/Programming/StrawberryPe +rl/c/bin/ -c "echo gcc_mswdll/minimal_sample_rc.o >> gcc_mswdll/minim +al.exe.rsp.tmp", ...) failed. makefile.gcc:221: pipe: No such file or directory process_begin: CreateProcess(NULL, D:/WinApps/Programming/StrawberryPe +rl/c/bin/ -c "echo gcc_mswdll/minimal_minimal.o >> gcc_mswdll/minimal +.exe.rsp.tmp", ...) failed. makefile.gcc:221: pipe: No such file or directory Can't open(GLOB(0x2f31a90), D:\WinApps\Programming\wxWidgets\lib\gcc_d +ll\msw\build.cfg): No such file or directory at ./Build line 66. MDOOTSON/Alien-wxWidgets-0.69.tar.gz D:\WinApps\Programming\StrawberryPerl\perl\bin\perl.exe ./Build -- N +OT OK Stopping: 'install' failed for 'Alien::wxWidgets'.
    An alternative would be Perl/Tk, but I have no experience with this. I've also seen Win32::GUI but again, no experience with this.

    Next to the fact that I'm missing experience with those GUI "languages", I see those modules are quite old and I'm wondering if it's still useful to step into such "unsure" development environment.

    Any suggestions?

    Best rgds,
Expression form of map or grep
3 direct replies — Read more / Contribute
by Lady_Aleena
on Jul 10, 2020 at 15:47

    As you might know, I have been using Perl::Critic on my code over the last several days. After I finished checking my code on the gentle setting, I kicked it up a notch and used stern. Well, Perl::Critic set on stern gave me screens full of problems, and the biggest one is I use the expression form of map and grep. I looked around the web to find out why.

    Here is my opinion that could be very wrong.

    All of the examples I found of the expression form of map and grep would lead to inevitable problems, and I can see why the writers of those examples would jump on using the block form for both. However, the one thing all of the examples had in common is the disuse of parentheses. I feel that if the expression form of a map or grep is used with parentheses, it is contained within them.

    The map below would lead to problems, since there is nothing containing the expression or on which list(s) the map is being applied.

    my @colors = qw(red yellow green cyan blue magenta); my @grey_scale = qw(white grey black); my @list = map "$_ beads", @colors, @grey_scale;

    However, I do not think this needs a block form to contain the map and list if parentheses are used.

    my @list = map( "$_ beads", @colors ), @grey_scale;

    Now the map is contained within parentheses, and @grey_scale does not get beads mapped to it. However, if one must use the block form, parentheses would still be needed to contain the mapped items.

    my @list = ( map { "$_ beads" } @colors ), @grey_scale;

    I think the expression form with parentheses is easier on the eyes, but it is just my opinion. I can understand using the block form if the map were more complex, however, I think I would write a separate subroutine instead of loading the block with more than two or three modifications and use the expression form.

    Converting from expression to block form is also problematic as it is not always as simple as the above would suggest, especially with grep. I have also found the expression form of grep to be easier to use, in one case (I can not remember the specifics) I could not get the block form of grep to work.

    If I use sort with map and/or grep on the same list, I will wrestle the block forms until I get the results I want, because in that case, it is easier on my eyes than trying to mix expression forms with the block of sort.

    I know I can ignore Perl::Critic's results on this and other issues, however, I do want code that is more acceptable by the community. So, I am trying to decide if I want to start wrestling with Perl on this or not. (I ran Perl::Critic on all of my modules, and it found 330 lines where I used the expression forms of map and grep, so this is fairly big to me.)

    I hope I am not too wrong about this.

    My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.16.3 or 5.30.0 on web host depending on the shebang.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
RFC -- Evolving Perl: a Decision Theory Approach to the Challenges of Perl 7
1 direct reply — Read more / Contribute
by thechartist
on Jul 07, 2020 at 14:16

    The announcement of Perl 7 has created a lot of activity in the various techology communities I follow. It has also lead to a lot of discussion and debate among a number of subsets of the Perl community.

    Last week we had a discussion on "software quality" in the Perl Programmers Facebook group. "Quality" is a term that is not defined whenever it pops up. I pointed out that "quality" for a typical "real world" programming problem can be seen as a Multiple Criteria Decision Analysis, or a Multiple Objective Optimization Problem, that attempts to balance the following:

    1. Validate that inputs are appropriately transformed into the correct/desired outputs.
    2. Handle errors, exceptions, etc.
    3. Does so in a computationally efficient manner (ie. time and space efficiency). The algorithm doesn't need to be provably optimal, but it should be suitable for the *known* needs of the application at the time of writing.
    4. Delivered in a verifiable/testable form as quickly as possible.
    5. Comprehensible to other team members.
    6. Able to be relatively easy to change, if application specification changes.

    I'm sure there are other objectives I omitted. I think it should be obvious that:

    1. these dimensions need to be traded off against one another and
    2. these criteria aren't all equally weighted. Context determines what criteria are most important in a particular time.

    From a formal point of view, there are generally no unique/optimal solutions, only sets of satisfactory ones (Multiple Criteria Decision Analysis).

    Some of the themes of the p5p messages after the announcement included:

    1. What is the new contract with Perl users re: backward compatibility?
    2. What should be done in newer versions of Perl to attract new users?
    3. What should be done to ease the implementation of new features, and reduce the complexity of the Perl interpreter, toolchain, etc.
    4. What can be done to facilitate a better process for the community to make better decisions?

    The conclusions I've come to (as a former Perl hater, now Perl convert) is:

    1. Perl as a technology, scales from small one-liner throw away scripts, to massive code bases that span decades. There aren't many other languages that can boast about that.
    2. Perl, as a community, has learned a lot of lessons in producing reliable software. These lessons become part of Perl culture, and produce better developers.

    In terms of point 4 above (Perl community process), I'd like to suggest borrowing some methods from the operations research/decision analysis communities (Tools for Decision Analysis).

    The criteria I see the Perl community attempting to balance are:

    1. Perl interpreter complexity. Certain things need to be changed to improve computational efficiency, ease maintainence, and enhance the language.
    2. CPAN backward compatibility. Too much breakage with CPAN, and we have a new language with no code base.
    3. Increasing use of Perl in newer areas (ie. attracting new users, especially newer developers who can hack on the toolchain).
    4. Teaching the language, and good software development practice generally.

    An approach worth considering can be seen in the Ada community. Initially standardized in 1983, each revision (1995, 2005, 2012) has been accompanied by a Rationale document, that describes the changes and the reasons for them. Most of the changes have been addiitions or extensions to the language.

    Any rationale for future versions of Perl will be a bit more challenging, in that some practices will need to be revised. To explain and defend such changes, an explicit, pairwise comparison of what criteria are improved, and how they are traded off vs. other objectives, needs to be considered.

    I personally would like to see Perl more involved in so-called "data science." My use case for Perl is statistical natural language processing to assist in the meta-analysis or evidence synthesis of research in health care specifically, but in applied science more generally. I believe those tools could be helpful in exploring the CPAN code base to collect empirical data on what features of Perl are most used, and which could be dropped with minimal loss.

    If I'm thinking about this correctly, the problem the Perl community faces is one known in the Prolog and logic programming communities as inductive specification recovery. If I were to translate the informal problem facing the Perl community into a formal statement, I'd say we are attempting to discover (induct) the Perl grammar that simultaneously:

    1. Reduces CPAN Breakages
    2. Reduces Perl interpreter code complexity

    Damian Conway has shown how hard this path is via human effort Three Little Words.

    To calculate these things require some metrics. I think the CPAN breakage is reasonably easy to calculate. But the interpreter complexity metric is something that should be given some considerable thought.

    With an explicit decision model, I believe we can use statistical methods from reliability theory and machine learning to develop software that will ease the burden of transitioning Perl to a more sustainable future.

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 making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2020-07-12 02:35 GMT
Find Nodes?
    Voting Booth?

    No recent polls found