Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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.

Quests
poll ideas quest 2021
Starts at: Jan 01, 2021 at 00:00
Ends at: Dec 31, 2021 at 23:59
Current Status: Active
3 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
CPANdeps end of life
on May 04, 2021 at 14:52
2 replies by choroba
    As announced at dev.to, another Perl service is about to shut down. Will any volunteers stand up to take it over?

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Perl Foundation Community Affairs Team Transparency Report
on Apr 26, 2021 at 08:36
6 replies by 1nickt

    "Following issues raised within the community, the Perl Foundation's Community Affairs Team (CAT) opened an investigation into community conduct. A second investigation was opened based on information discovered during the first investigation."
    . . .

    View blog post

    Note: The title of this post has been updated; previously it made reference to an earlier event which is not actually referenced in the CAT report. Interested readers can do their own research to discover the context of and reaction to the report. The author of this post felt that a "permaban" on a Perl contributor was newsworthy in itself.


    The way forward always starts with a minimal test.
Supplications
Attempting to use $_ in "sub" inside "map"
1 direct reply — Read more / Contribute
by NetWallah
on May 08, 2021 at 00:36
    I'm trying to automate building a dispatch table - or at least, to minimize keystrokes.

    Please suggest ways to achieve the desired result:

    use strict; use warnings; my %dispatch = ( normal => sub{"$_[0] Normal dispatch"}, map( {$_ => sub{"$_[0] Sub returns $_"} } qw| Uno Dos tres|), ); print $dispatch{"normal"}->(0),"\n"; # 0 Normal dispatch (as expected) + print $dispatch{"Uno"}->(1),"\n"; # WANT: "1 Sub returns Uno" print $dispatch{"Dos"}->(2),"\n"; # WANT: "2 Sub returns Dos"
    This currently prints:
    0 Normal dispatch Use of uninitialized value $_ in concatenation (.) or string at .\test +dispatch.pl line 5. 1 Sub returns Use of uninitialized value $_ in concatenation (.) or string at .\test +dispatch.pl line 5. 2 Sub returns
    Also - is there a NAME for what I am attempting ? "Early evaluation of $_" ?

                    "Avoid strange women and temporary variables."

PDF::API2 external objects
1 direct reply — Read more / Contribute
by dd-b
on May 07, 2021 at 23:40

    It appears that external objects (specifically, image files placed on the various pages) are not actually read until the pdf->save() call at the end. This may be problematic, in that I'm playing with a script that may generate a rather LARGE PDF containing more than 10,000 images.

    I'm wondering if anything like the $pdf->finishobjects(@obj) call might help; but the documentation doesn't really tell me very much about it!

    It does look like this module lets you insert pages in any order, and write on pages in any order, so maybe in fact nothing is really done until the end. It might not matter; I'm not actually that worried about the temp directory capacity on modern systems, and a BOTE calculation suggests the sum of the image files, at the size I'm currently proto-typing at, is a very few gigabytes. (Temp files are written out as a necessary step in re-scaling the files to sizes suitable to their appearance in the PDF; yes, using GD you can import an image file, re-scale it in memory, and put that directly into PDF::API2, without going through any temporary files, and it even works...but I was kind of shocked to discover that that was TWO ORDERS OF MAGNITUDE slower than using Image::Imlib2 to read, rescale, and write the image to a temp file and then reading it using the PDF::API2 method.)

    (As a side note--I'm kind of shocked how far I've gotten with this since starting to commit code this morning. PDF::API2, despite some documentation issues, which are frequently commented on, seems to be fairly easy to get somewhere with.)

CSV to XML
4 direct replies — Read more / Contribute
by fmcroft92
on May 07, 2021 at 15:40

    Hi, Iím very new to Perl and programming generally. I have a real world problem whereby I want to convert a CSV file into an XML file. The structure of the xml file I need to create can be found here https://www.gov.uk/government/publications/co-ordinated-admissions-2021-series-17-files.

    Would anyone be able to give me any guidance on how I could go about this and where to start?

    Thank you.

Subs calling themselves
2 direct replies — Read more / Contribute
by Bod
on May 07, 2021 at 08:43

    Continuing from my previous discussion about connecting to LinkedIn - see Injecting a value into HTTP::Header

    I have managed to authenticate with LinkedIn using LWP::Authen::OAuth2::ServiceProvider::LinkedIn which I am writing. This is used by LWP::Authen::OAuth2. LinkedIn doesn't obey the OAuth2 standard which is why there was a need to add extra information.

    But now I am having difficulty posting anything to LinkedIn and I am getting an error from LWP::Authen::OAuth2
    Can't call method "request" on an undefined value at /home/shoples1/perl5/lib/perl5/LWP/Authen/OAuth2.pm line 107.

    I've looked at the source code of LWP::Authen::OAuth2 to try and see what I need to do differently to make this work. However, I cannot fathom how that module is supposed to work. Clearly, it does work and it is my understanding that is missing because it is a working module. But these two subroutines just seem to be calling each other:

    sub request { my ($self, $request, @rest) = @_; return $self->access_token->request($self, $request, @rest); # <- +line 107 } sub access_token { my $self = shift; return $self->{access_token}; }
    Having gone through the authentication and obtained a token, I am trying to make a post using the following code. I am not expecting it to actually make a post yet but I was expecting to get an error from LinkedIn and not an error from Perl.
    my $params = { 'content' => { 'title' => 'Test Title', 'descrition' => 'Test message', }, }; my $res = $linkedin->post('https://api.linkedin.com/v2/shares', $param +s); if ($res) { print "Content-type: text/plain\n\n"; print $res; exit 0; }
    Can you help me understand what the two subroutines in LWP::Authen::OAuth2 are actually doing?

Unwanted cloning of array elements
3 direct replies — Read more / Contribute
by oakbox
on May 07, 2021 at 06:18

    I have a real pickle of a problem here and I'm not even sure how to googlefoo this one. I have an array reference. I am pushing hashrefs onto it. These arrays are being cloned if they are substantially *similar*. If they are different ENOUGH, a new, unique, hashref is pushed onto the arrayref. If they are too similar, then they are cloned? I'm not even really sure about *how* different the hashrefs need to be before the elements are not cloned.

    Here is some code:

    #!/usr/bin/perl use strict; my $Action; my $piece; $piece->{this} = 123; $piece->{that} = 'some text'; foreach my $other (111...113){ $piece->{theother} = $other; push(@{$Action}, $piece); } use Data::Dumper; print Dumper($Action); foreach my $section (@{$Action}){ print Dumper($section) . "\n"; }

    What I EXPECT to get out of this is an arrayref of hashreferences that are slightly different (different values for 'theother' key).

    $Action->[ { this => 123, that => 'some text', theother => 111 }, { this => 123, that => 'some text', theother => 112 }, { this => 123, that => 'some text', theother => 113 } ]

    What the actual output is:

    $VAR1 = [ { 'that' => 'some text', 'theother' => 113, 'this' => 123 }, $VAR1->[0], $VAR1->[0] ]; $VAR1 = { 'that' => 'some text', 'theother' => 113, 'this' => 123 }; $VAR1 = { 'that' => 'some text', 'theother' => 113, 'this' => 123 }; $VAR1 = { 'that' => 'some text', 'theother' => 113, 'this' => 123 };

    What is going on here? This seems like some sort of memory optimization gone wrong. Is there any way I can 'force' perl to *do what I mean* in this case?

[raku] what accessors are actually autogenerated for @.array attributes?
1 direct reply — Read more / Contribute
by tomgracey
on May 06, 2021 at 10:22

    Hello PerlRaku Monks

    I have another (absurdly basic) Raku question. Consider the following:

    class Fish { has @.scales is rw; } my $fish = Fish.new; $fish.scales('green','blue','yellow');

    This doesn't work. I get:

    Too many positionals passed; expected 1 argument but got 4

    The "1 argument" it appears to be expecting seems to be self. ie it seems specifying @.scales creates only the get accessor. Is this correct? Do we have to create our own set accessors for array-type attributes?

    I may be looking in the wrong place, but I could not find any documentation on exactly what accessors are autogenerated - the docs seem to just say "specify the period twigil to have accessors autogenerated".

    Part of my problem may be that I am not familiar enough with the various inspection methods. Possibly there is a way to see exactly what methods are being created. For example the ^methods meta-method does return a list of methods, but without any accompanying information - e.g is it a multimethod etc. So scales would come up in the list if $fish.^methods is called, but it would seem only once regardless if there is a setter. Is anyone aware of a way of getting a more detailed list?

    Sorry again for the basic question, but sometimes it seems better to get some direct feedback rather than trawling endlessly in the hope of finding examples. (I looked through vast swathes of code for an example of setting an array after the object has been created and didn't happen on any at all. Plenty of setting it via new of course. Not sure if I was just unlucky.)

    Anyway thanks in advance for your help

Windows set PERL5LIB environment variable
2 direct replies — Read more / Contribute
by vinoth.ree
on May 06, 2021 at 04:58
    Hi Monks,

    I am trying to set PERL5LIB environment variable in windows10 with multiple paths, like below, export PERL5LIB="${HOMEDRIVE}\\Perl64\\lib;${HOMEDRIVE}\\Perl64\\site\\lib" but the ':' character after the Drive is getting removed from the PERL5LIB value like looks like C \Perl64\lib;C \Perl64\site\lib and modules are not getting loaded.

    Is it windows behavior to remove the ':' character? Actually its a common shell script will setup the environment before I invoke the actual bunch of perl scripts, otherwise I would have used use lib "Path" inside the script to load the modules.


    All is well. I learn by answering your questions...
use 5.32
1 direct reply — Read more / Contribute
by plvicente
on May 05, 2021 at 13:33

    Hello! Can I use 5.32 as strict keyword? Like this? Or should i use 5.010!?

    #!/bin/perl use strict; use 5.032;
Perl 5 numeric type and simplifications
6 direct replies — Read more / Contribute
by pango
on May 04, 2021 at 21:42
    Hi Monks,

    I have a question regarding Perl's numeric type, and how (I assume) it simplifies the value before storing/printing them.

    For example:

    use warnings; my $foo = 50.0; warn $foo;

    would display 50, rather than 50.0. I'm interested in knowing if this is always the case (can I rely on this behaviour of simplifying the number?), where can I read more about this if it is documented. I tried searching for more information in https://perldoc.perl.org/perlnumber but I couldn't find anything specific to this.

    I am only interested because I find this an easy way to remove trailing decimal zeroes, and if I can get away with not using sprintf then that would be great.

Challenge: Generate a glob patterns from a word list
5 direct replies — Read more / Contribute
by choroba
on May 03, 2021 at 18:41
    (Inspired by this StackOverflow question.)

    You are given a list of words. Find the shortest glob expression generating the words in the list. The glob expression should only use curly brackets and commas, no spaces, no wildcards.

    e.g.

    #! /usr/bin/perl use warnings; use strict; use Test::More; sub list2glob { ... } is list2glob('a', 'b'), '{a,b}'; is list2glob('ab', 'ac'), 'a{b,c}'; is list2glob('aXb', 'aYb'), 'a{X,Y}b'; is list2glob(qw( a1b3c a1b4c a2b3c a2b4c )), 'a{1,2}b{3,4}c'; is list2glob(qw( /ab/ef/ij/kl /ab/ef/ij/mn /ab/ef/ij /ab/gh/ij/kl /ab/gh/ij/mn /ab/gh/ij /cd/ef/ij/kl /cd/ef/ij/mn /cd/ef/ij /cd/gh/ij/kl /cd/gh/ij/mn /cd/gh/ij )), '/{ab,cd}/{ef,gh}/ij{/{kl,mn},}'; is list2glob(qw( abdel abdelmn abdelmo abdfgkl abdfgklmn abdfgklmo abdfghkl abdfghklmn abdfghklmo abdfgijkl abdfgijklmn abdfgijklmo acdel acdelmn acdelmo acdfgkl acdfgklmn acdfgklmo acdfghkl acdfghklmn acdfghklmo acdfgijkl acdfgijklmn acdfgijklmo )), 'a{b,c}d{e,fg{,h,ij}k}l{,m{n,o}}'; done_testing();

    I've tried several times, but I can't get it right. It gets much more complex than it seems, or maybe I'm doing something wrong. Any ideas, solutions, insults?

    Update: What do I mean by "shortest"? The curly brackets and commas don't count, just count the other characters.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Using regex in file glob ?
4 direct replies — Read more / Contribute
by Wiggins
on May 03, 2021 at 09:19

    Some times things are so obvious that they are not documented. But who can tell?

    I am looking for a file in a directory using the 'glob' <>. within that glob is a non-simple RE.

    my @possible = <${pathHi}(.*[_-]?RTM[_-]).*[.]xlsx>; #perl glob
    This throws no errors, but never returns anything either. I am looking for something like:
    RTM.xlsx RTM-v3.3_.xlsx system_2_RTM_v3-4.xlsx system 3-RTM.xlsx #yes, embeded spaces in file names

    As I searched, the only example was '*', and no description of what could be used, or what internals would be doing the processing.

    Pointers to some docs?

    It is always better to have seen your target for yourself, rather than depend upon someone else's description.

Problems Passing an object to a function that was passed to a module
1 direct reply — Read more / Contribute
by Oliver.Doerr
on May 03, 2021 at 04:33

    Hi,

    I'm searching for a part of wisdom, that I was not able to find in the Internet. So it is to good hidden for me;-)

    So what I'm trying to build is a perl module that does a lot of work for various perl scripts for me. However there is one little kind of code (a simple parser), that has to be provided by the calling script. So I have code like this inside the script as parser...

    sub parseGroupDescription { my $groupObj=shift; # my problem $groupObj is always undef / $g +roupObj is Net::LDAP:Entry my $groupName=get_attribute($groupObj,"erldapservicegroup"); my $groupDesc=get_attribute($groupObj,"description"); my $response; $response->{"name"}=$groupName; return $response; } # sub parseGroupDescription
    I'm calling the method inside my main script using
    my $data=$zbdbObj->fetchData($ldapConn,$serviceFilter,$groupFilter,sub + {parseGroupDescription});
    The perl module has code like
    sub fetchData { my $selfObj=shift; my $ldapConn=shift; my $serviceFilter=shift; my $groupFilter=shift; my $parseFunction=shift; ... foreach my $group ($allGroups->entries) { print get_attribute($group,"erldapservicegroup")." "; my $response=&$parseFunction->($group); # $group is a Net:: +LDAP:Entry object and $parseFunction a reference on the function of t +he main script my $groupName=$response->{"name"}; $serviceDataObj->{"groups"}->{$groupName}=$groupName; } # foreach my $group ($allGroups->entries) } # sub fetchData

    I could see that my parser is called within this construct, however I was not able to find a way to pass the value of $groupObj to the parser.

    Any ideas?

    Regards

    Oliver

    PS: This is a simplyfied version of my code
Meditations
History of PerlMonks' Perl News
No replies — Read more | Post response
by jdporter
on May 04, 2021 at 16:37

    History of PerlMonks' Perl News

    Originally, the Perl News section of the site was not a place where ordinary monks could post. Rather, it was designed to be a local "feed" of Perl-related news extracted from another site. That other site was called Perl News, at news.perl.org.

    Posts to the section were created in the name of a 'bot' account, perlnewsbot. (Presumably, perlnewsbot was the actual name of the automated background process. In all likelihood, it was vroom who created and ran the perlnewsbot.

    vroom announced New Perl News Section on 2000-07-21, and perlnewsbot made its first post that same day.

    news.perl.org was, of course, already in operation by then. the earliest snapshot in the Wayback Machine is dated 2000-01-05.

    *Confusingly, the perlnewsbot user account has a creation date of 2000-07-26 — several days after its first few posts. One possible explanation is as follows: Initially, posts were being inserted in the Perl News section by a different bot user or by some process outside of the perlmonks user-level framework. After the perlnewsbot user was created, the ownership of the prior existing posts was transferred to him. However, this is conjectural.

    perlnewsbot's run only lasted a few months, however.

    Its last post was on 2001-02-16, apparently having been halted even before news.perl.org went dark.

    The last post on news.perl.org was on 2001-03-18, with the following item:

    See use Perl;

    Perl News is going away soon (one might argue it already has :). use Perl is this site's sister site, having all the same news, plus reviews, articles, discussions, and more. The coincidence of the technical difficulties of this site and the imminent migration of use Perl to its new home makes now a good time to finalize the closing of Perl News.
    Indeed, barely a month later news.perl.org was gone.

    Even though use.perl.org - the site called use Perl; - was the ostensible replacement for news.perl.org, at least as a source of news, the perlnewsbot was never updated to pull news from use.perl.org.

    (Interestingly, use.perl.org met a similar fate a few years later. The last post there, announcing its imminent shutdown, was on 2010-09-08.)

    vroom opened up the Perl News section for posting by ordinary users in late May of 2002. Prior to that time, only perlnewsbot was able to post there. (vroom posted there himself once or twice before that, using his godly powers. The couple other posts you now see in that section prior to that date were originally posted in other sections and later moved to Perl News.)

    A noteworthy figure in all of this is Chris "pudge" Nandor. He was the man behind news.perl.org and use.perl.org. He was one of the lead developers of Slash, the perl-based engine which powered both Slashdot and use.perl.org. Of course, Slash was also the predecessor of the Everything Engine, upon which PerlMonks is built. Both are products of the tiny outfit called Blockstackers Intergalactic (BSI). Sound familiar? That is where vroom, nate, and other early creators of PerlMonks were working at the time. However, pudge says that he didn't really know those guys, even though he was in the same place at about the same time. Different projects. Here's what he told me in a private correspondence:

    I wasnít involved in perlmonks much, but I did news.perl and use.perl. IIRC perlmonks was based on Everything, which was a separate project from Blockstackers, which also created Slash, from which Slashdot and use Perl resulted.


    Relevant chronology:

    • 2000-07-21 - New Perl News Section - vroom creates the perlnews nodetype and dbtable. He posts an announcement, saying that perlnewsbot "just sucks news from the RDF from news.perl.org".
    • 2000-07-26 - Perl News Going Away? - perlnewsbot posts here the article from news.perl.org about that site's impending demise.
    • 2001-01-09 - Perl News Credits - KM alludes to a discussion he had with pudge about it.
    • 2001-02-16 - YAPC::Europe Set for Amsterdam in August - perlnewsbot's final post.
    • 2001-04-13 - The PerlNewsBot - A user notices that perlnewsbot is no longer posting to Perl News. A commenter suggests that the bot could be redirected to use.perl.org.
    • 2001-06-04 - Is brother perlnewsbot ill? - Another exchange almost identical to the preceding.
    • 2001-06-23 - News section not being kept current? - A user notes that the section is inactive and suggests opening it up to general users, with possibly a level requirement.
    • 2001-07-28 - Why no new news? - A user notes that the section is inactive. In a comment, the OP says" "if there's no automatic news gathering (ok fine), then why doesn't vroom (or whoever) open up the news area to manual posted news?"
    • 2001-08-06 - Member Submitted News - A user suggests opening up the Perl News section to posting by general users.
    • 2001-10-21 - randomnode - (patch) - vroom creates the first patch to mention perlnews (node type) by name in its code.
    • 2001-11-03 - New use for old news - A user suggests opening up the Perl News section to posting by general users.
    • 2002-02-11 - What's happening with Perl News? - "Since it appears to be dead, Perl News should either be killed or opened up to general postings." A commenter again suggests that the bot could pull news from use.perl.org.
    • 2002-02-22 - Make (Perl News == Use.Perl.Org) Or Is This Heresy? - A user suggests that the Perl News section link directly to use.perl.org, vs reposting content here.
    • 2002-04-26 - "Perl News" is old - A user notes that "the most recent news in the Perl News node date back to one year ago."
    • 2002-05-07 - Posting Unrelated News Items - A user suggests reactivating Perl News as a "normal" section (rather than mirroring off-site news stories) where monks can post links to relevant stories." This sparked a surprising amount of debate.
    • 2002-05-24 - tye notes in the editors' wiki:
      I fixed several problems with the (apparently rather hastilly) reopened Perl News section. There is one potentially ugly problem remaining...

      Since the work to set up the (unduely complicated) "approval link type" and related baggage has not been done, you can't "approve" Perl News nodes. This means that the approval nodelet won't show. Which means that some ppl can move a node to Perl News after which only editors will be able to move it anywhere else. The best solution is probably to create all of the baggage and make Perl News items require approval.

      You have been warned. Also, if this becomes a point of abuse before an enterprising god gets around to adding "approval" for Perl News, then the ability to move to/from Perl News can very quickly be taken away by deleting one line from writeupmover.
      At the same time, in the pm-port wiki:
      I fixed several things wrong with Perl News, which included changes to: perlnews (the node type), Perl News, perlnews display page, preview settings, vote settings, writeupmover, and perhaps a few others.

      The first problem was that adding new Perl News actually added new poetry. Of course, I noticed this because someone added news so I wanted to move it into the proper section. However, the node type of perlnews uses the dbtable of perlnews in order to add a linklocation field which makes it impossible to simply "move" to/from that node type. But search internal code shows that this extra field is not used currently so I changed the node type to not use that dbtable and then made "Perl News" one of the available move-to types. And I made it so you can vote on "Perl News" nodes.

      Since the work to set up the (unduely complicated) "approval link type" and related baggage has not been done, you can't "approve" Perl News nodes. This means that the approval nodelet won't show. Which means that some ppl can move a node to Perl News after which only editors will be able to move it anywhere else. The best solution is probably to create all of the baggage and make Perl News items require approval.
      Oddly, I don't see any patches from tye (nor tye&amp;) in that timeframe, nor any patches to any of the nodes he mentioned. I believe he must have mucked with all those codes directly, using godly powers. (He became a god on 2002-02-01.)
    • 2002-05-24 - Dr. Damian Conway to speak at Dallas/Ft. Worth Perl Mongers meeting in June - This post by atcroft in the Perl News section was probably originally in Meditations and then moved. I think so because there are records in the db showing that it was at one point "approved", yet perlnews never needed approval (at that time).
    • 2002-05-26 - Perl News reopened - vroom's announcement: "I've reopened Perl News. You can now post Perl News stories there. Currently approval isn't necessary." Unfortunately, modifications to a nodetype definition (e.g. its authorized creators & writers) are not tracked and do not use the patch system. maintenances are; but unfortunately perlnews did not get its sole maintenance - perlnews maintenance create - until three months later (2002-08-23).
    • 2002-05-26 - Boston Perl Classes - uri posts what is likely the first human-user submission directly to the newly opened Perl News section. Its records in the db show no evidence of having been approved.
    • 2002-05-26 - Voting in Perl News - A user thanks vroom for reviving the Perl News section, and offers this insight:
      "One of the reasons it was originally taken out of commission was that many people thought http://use.perl.org did a better job of providing Perl-related news. While use.perl.org is an excellent site, it focuses on larger stories and probably wouldn't publish most module releases and other small events. I think Perl News would be an excellent place to announce these smaller events."
    • 2002-05-31 - Perl Monks User Search - (patch) - VSarkiss submits a patch to Perl Monks User Search "so nodes in the newly re-opened Perl News will show up"; he notes it in the pmdev wiki. Interestingly, this patch was never applied; and also interestingly predates any other patches to Perl Monks User Search! Even so, the code was updated to include perlnews at some point before the first applied patch.
    • 2002-08-23 - perlnews maintenance create - (patch) - the first patch to mention "news" in its reason.
    • 2010-10-13 - What exactly counts as "Perl News"? - Interesting commentary, especially by tye.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2021-05-09 06:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (100 votes). Check out past polls.

    Notices?