Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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
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
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."

Phishing Attack on CPAN Authors
on Jan 04, 2021 at 18:08
1 reply by hippo

    As announced by TPF. Take care, everyone.


    🦛

Supplications
Text::Summarizer fails on Windows 10
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jan 16, 2021 at 13:21

    Hello

    I am trying to install on Windows 10, Strawberryperl v5.28.1, the module Text::Summarizer. I get the following - for my knowledge - strange error. Do you know what can I do to solve this issue?

    cpanm Text::Summarizer --> Working on Text::Summarizer Fetching http://www.cpan.org/authors/id/F/FA/FAELIN/Text-Summarizer-2. +01.tar.gz ... OK Could not create directory 'C:\Users\TE\.cpanm\work\1610820965.16324\T +ext-Summarizer-2.01\Corpus\written\newspaper:newswire' for 'Text-Summ +arizer-2.01/Corpus/written/newspaper:newswire': mkdir C:\Users\TE\.cp +anm\work\1610820965.16324\Text-Summarizer-2.01\Corpus\written\newspap +er:.: Invalid argument; Die Syntax f³r den Dateinamen, Verzeichnisnam +en oder die Datentrõgerbezeichnung ist falsch at C:/Strawberry/perl/l +ib/Archive/Tar.pm line 819. at C:\Strawberry\perl\bin\cpanm.bat line 132. Could not extract 'Text-Summarizer-2.01/Corpus/written/newspaper:newsw +ire' at C:\Strawberry\perl\bin\cpanm.bat line 132. ==> Found dependencies: Module::Build Found Module::Build 0.4231 which doesn't satisfy 2.01. ! Installing the dependencies failed: Installed version (0.4224) of Mo +dule::Build is not in range '2.01' ! Bailing out the installation for Text-Summarizer-2.01.
mysteries of regex substring matching
4 direct replies — Read more / Contribute
by smile4me
on Jan 15, 2021 at 16:42

    We all know that "In list context, a regex match returns a list of captured substrings." And, we also know "Numeric quantifiers express the number of times an atom may match. {n} means that a match must occur exactly n times." So can the numeric quantifier work with the captured substrings?

    perl -E '$s = q[AAD34017837201D98AAED18778DEF993]; say length($s), " ", $s; @m = $s =~ /(....)(....)(....)(....)(.+)/; say "", join("-",@m);' # 32 AAD34017837201D98AAED18778DEF993 # AAD3-4017-8372-01D9-8AAED18778DEF993

    In contrast, the following regex uses a numeric quantifier but does not work as above:

    perl -E '$s = q[AAD34017837201D98AAED18778DEF993]; say length($s), " ", $s; @m = $s =~ /(....){4}(.+)/; say "", join("-",@m);' # 32 AAD34017837201D98AAED18778DEF993 # 01D9-8AAED18778DEF993

    So, is there a way to use capture groups to match multiple times like separate groups does in the first example?

SSL certificate store for a Perlbrew install
2 direct replies — Read more / Contribute
by chrestomanci
on Jan 14, 2021 at 11:48

    Greetings wise brothers, I seek your advice on secret communication an how we can be sure we know who we are talking to.

    Specifically, I am trying to get LWP::UserAgent running inside a locally compiled perlbrew install, to accept a corporate root cert.

    At my company, IT have created a private SSL certificate keypair, and used it to sign the ssl certs on numerous internal servers. They also publish the public half of the SSL cert which (on ubuntu) I have installed in /etc/ssl/certs/ where it is accepted by system perl, firefox, wget etc.

    For some reason the corporate public certificate is not accepted by a perlbrew install of perl 5.10 that I have compiled localy. Do I need to install the corporate root cert somewhere else for perlbrew to accept it?

    Code to reproduce

    use strict; use warnings; use XML::Simple; use LWP::UserAgent; use Data::Dumper; my $url = "https://--- REDACTED ----"; my $parser = new XML::Simple; my $ua = new LWP::UserAgent; # $ua->ssl_opts( verify_hostname => 0 ,SSL_verify_mode => 0x00); my $req = new HTTP::Request('GET', $url); my $resp = $ua->request($req); # print "Result from fetching $url : " . Dumper($resp); if( $resp->is_success() ){ # print "Result content: ". $resp->content; eval{ my $parsed_xml = $parser->XMLin($resp->content, ForceArray => +['publishedfile']); }; if( $@ ){ print "Error parsing XML: $@"; } else { print "File downloaded and XML parsed OK" } } else { die "Error fetching $url : ".$resp->message; }

    This code works fine using Ubuntu's system perl on all the versions of Ubuntu I could find. It also works if I uncomment the $ua->ssl_opts( verify_hostname => 0 ,SSL_verify_mode => 0x00); line, But it fails on line 35 with  Can't connect to REDACTED:443 (certificate verify failed) at scripts/dev/test_ssl_download.pl line 35. if I use perlbrew perl.

    Any ideas?

    NB: I asked this question in chatterbox about an hour ago, but did not get a reply, so I am re-posting as a perl question.

Question regarding Time::Piece and timezones
4 direct replies — Read more / Contribute
by atcroft
on Jan 14, 2021 at 01:02

    The documentation for Time::Piece in 5.30.x states the following:

    Date Parsing
    Time::Piece has a built-in strptime() function (from FreeBSD), allowing you incredibly flexible date parsing routines. For example:
    my $t = Time::Piece->strptime("Sunday 3rd Nov, 1943", "%A %drd %b, %Y"); print $t->strftime("%a, %d %b %Y");
    Outputs:
    Wed, 03 Nov 1943
    (see, it's even smart enough to fix my obvious date bug) For more information see "man strptime", which should be on all unix systems. Alternatively look here: http://www.unix.com/man-page/FreeBSD/3/strftime/

    The link includes the following conversion specifications:

    %a is replaced by national representation of the abbreviated weekday name.
    %d is replaced by the day of the month as a decimal number (01-31).
    %b is replaced by national representation of the abbreviated month name.
    %Y is replaced by the year with century as a decimal number.
    %T is equivalent to ``%H:%M:%S''.
    %H is replaced by the hour (24-hour clock) as a decimal number (00-23).
    %M is replaced by the minute as a decimal number (00-59).
    %S is replaced by the second as a decimal number (00-60).
    %Z is replaced by the time zone name.
    %z is replaced by the time zone offset from UTC; a leading plus sign stands for east of UTC, a minus sign for west of UTC, hours and minutes follow with two digits each and no delimiter between them (common form for RFC 822 date headers).

    The page for strptime on the same site says, "The strptime() function parses the string in the buffer buf according to the string pointed to by format, and fills in the elements of the structure pointed to by timeptr. The resulting values will be relative to the local time zone. Thus, it can be considered the reverse operation of strftime(3)."

    I created the following test code as tp_test.pl:

    #!/usr/bin/perl # vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: use strict; use warnings; use Carp; use Time::Piece; $SIG{__WARN__} = sub { Carp::cluck @_; }; $SIG{__DIE__} = sub { Carp::confess @_; }; $| = 1; my $t = localtime; my $pattern = "%a, %d %b %Y %T %Z"; my $str = $t->strftime( $pattern ); print "Time is:\n", $str, "\n"; # Format: Wed, 13 Jan 2021 17:22:23 CST my $u = Time::Piece->strptime( $str, $pattern, ); print "Time is:\n", $u->strftime( $pattern ), "\n";

    I tested the code on the following three (3) platforms:

    • 5.30.1 under MSWin/x86_64 (Strawberry/BerryBrew)
    • 5.30.3 under MSWin/x86_64 (Cygwin64)
    • 5.30.3 under Linux/x86_64
    When I execute the script above, I get the following on all three platforms (differing only by the path to Piece.pm):
    $ perl ./tp_test.pl Time is: Wed, 13 Jan 2021 22:21:49 CST Error parsing time at /usr/lib64/perl5/Time/Piece.pm line 597. at ./tp_test.pl line 11. main::__ANON__("Error parsing time at /usr/lib64/perl5/Time/Piece.pm line 597.\x{a}") called at /usr/lib64/perl5/Time/Piece.pm line 597 Time::Piece::strptime("Time::Piece", "Wed, 13 Jan 2021 22:21:49 CST", "%a, %d %b %Y %T %Z") called at ./tp_test.pl line 23 $

    Expected output:

    $ perl ./tp_test.pl Time is: Wed, 13 Jan 2021 22:21:49 CST Time is: Wed, 13 Jan 2021 22:21:49 CST $

    The behavior also appears to occur if I change my $t = localtime; to my $t = gmtime; as well, where the timezone is then 'UTC'. If it were only occurring under Cygwin and Strawberry, my first guess would be MSWin-related, but since I am seeing it on a Linux system as well, I'm not sure where to look for the cause of the issue.

    Thoughts?

Detect whether a writeable filehandle has closed?
10 direct replies — Read more / Contribute
by jdporter
on Jan 13, 2021 at 12:26

    In my perl program I open a subprocess for writing via a pipe. It appears that this child process can decide to exit at times I don't expect. Is it possible to detect that the filehandle to the pipe is no longer usable? As it is, I now get SIGPIPE occasionally, but it seems to happen later, after I've possibly already written (tried to write) additional lines to the pipe. I want something synchronous.

    I've seen Scalar::Util's openhandle function. Does it work on pipe handles, opened for writing?

    TIA!

    I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.
First steps with Marpa::R2 and BNF
5 direct replies — Read more / Contribute
by Discipulus
on Jan 13, 2021 at 08:35
    Hello nuns and monks!

    I've get off the rust over my hands with a toy project recently uploaded to CPAN. It is a dice roller system.

    After ~100 lines of coding, in the above module I had a sudden desire to use Marpa::R2 to accomplish the task of parsing dice expressions. But I terminate my module without any grammar and it accept dice expressions like:

    3d6 # simplest one 3d6+3 # with a result modifier 3d8r1 # reroll and discard any 1 3d8rlt3 # reroll and discard any lesser than 3 3d8rgt6 # reroll and discard any greater than 6 3d8rgt6+2 # reroll and discard any greater than 6 and add +2 to the f +inal result

    ..and so on. See the synopsis of my module for more examples.

    Now I want to parse these expressions with Marpa::R2 and I produced cool code I'm proud of you can review at the end of the post.

    Marpa and BNF in general has a lot of documentation and well.. I did not read it all :) It is damn complicated and the enormous amount of documentation produced by Marpa::R2 author is invaluable but also sparse and not precisely destinated to beginners. Or I'm dumb.

    Anyway I have some questions and I'd like simple answers.

    1 - Marpa uses regexes but..

    RHS (Right Hand Symbol) are often like: digits ~ [\d]+ but it seems only character classes can be used. I tried with:  something ~ [(?:this|or|that)]+ but it seems is not the correct usage.

    What can be put at the end of a definition chain?

    2 - Optional terms

    In the below example Dice_with_modifier_x rule works but in the Dice_with_modifier_r I wanted to introduce optional terms: it must accept all these expressions:  3d6r1 3d6rgt4 3d6rlt3 so the r will be always present but followed by an optional gt or lt (greater than and lesser than).

    When I pass 3d8r1 and 3d8rgt1 I get different sized lists ( as shown by dd by Data::Dump ):

    # 3d8r1 modifier_r received: ({}, { die_type => "1d8", rolls => [8, 1, 7] }, " +r", 1) # 3d8rgt1 modifier_r received: ({}, { die_type => "1d8", rolls => [4, 8, 1] }, " +r", "gt", 1)

    Should I work on the size of the list? In my head I'd like something Optional_Modifier_Comparison and if it is not present assume eq as default.

    How must I treat optional eventually empty terms?

    I have put Die_Modifier_Comp ~ 'gt' | 'lt' but wonder if this is the way. Anyway I tried Die_Modifier_Comp ~ 'gt' | 'lt' | '' and it dies.

    3 - Returned structures

    I put :default ::= action => [name,values] and I see that my subs where I return a hashref are modified and the actual return structure is \["Dice_Expression", { die_type => "1d4", rolls => [2] }] if I remove name from the default action it eliminates the "Dice_Expression" part. Anyway a reference to an arrayref is returned and then I have to write ugly things like: $$$new[1]->{rolls}->[0]

    How can I use name in a profitable way? There is a way to simplify returned structures (well I can unwrap it at the begin of the sub..)?

    Below my actual code.

    Thanks for reading

    L*

    PS January 16 2021 I published A dice roller system with Marpa::R2

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
convert tags to punctuation
3 direct replies — Read more / Contribute
by Anonymous Monk
on Jan 12, 2021 at 19:49

    I have a large text file to process. When I view it with the 'more' filter I see a lot of these tags: <91> <92> <93> <94> <97> I can see from the context they are of a grammatical nature. Is there a nice way to convert these tags into punctuation marks etc?

Perl AJAX jQuery, js file
4 direct replies — Read more / Contribute
by monx663
on Jan 11, 2021 at 07:29
    This is not exactly a Perl question but, I'm using Perl as the backend programming language that creates HTML so...

    I am incorporating AJAX on a CMS written in Perl which has been stable for years. One of the backoffice pages of this CMS, shows a list of items that expose actions that can be carried out on this item. One of these actions is Activate/Inactivate. This is just an icon wrapped around that would call the right Perl script on the server and switch the items' status. I am trying to do this with AJAX/JSON jQuery inline, rather than enforcing a full page reload with the traditional href link to a CGI script.

    I have written a script on the server that responds to AJAX called with jQuery and completes the desired action and returns dynamic results that update the corresponding hardcoded (div2log) DIV element of the page that called it. <DIV id="div2log"></DIV>

    What I would like to do is include the JSON/jQuery stuff in a .js (Javascript) file on the server and only include references to this file where jQuery/AJAX is needed for any item.

    I have created a js file that contains:

    <script>
    $(document).ready(function(){
       $("button").click(function(){
          $.ajax({url: "/cgi-bin/ajax.pl", success: function(result){
             $("#div2log").html(result);
          }});
      });
    });
    </script>

    But I am not sure how to reference it, and pass it the params that I would have passed to a script using /cgi/script.pl?paramA=1&paramB=2&param3=3 and I am not sure how to pass it the HTML ID of the DIV that it must update with the visual result of its action on the server.

    Does my question make sense?

    Cheers,
    Kostas
Cool Uses for Perl
A dice roller system with Marpa::R2
1 direct reply — Read more / Contribute
by Discipulus
on Jan 16, 2021 at 09:49
    Hello folks!

    I recently asked for your wisdom in First steps with Marpa::R2 and BNF and I got nice answers. I'm playing with dice in these days as you can see in the post is rand random enough to simulate dice rolls?. The module I finally crafted as toy project is Games::Dice::Roller (with its gitlab repository).

    But I had a sudden desire to reimplement the whole in Marpa::R2 and evolvig duelafn's example and following precious GrandFather's suggestions I ended with the following working code.

    I left in it a lot of debug messages in case someone comes here to look for Marpa::R2 examples.

    It actually mimicry the beahaviour of my Games::Dice::Roller for input received (it still does not accept multistring arguments like 3d6 4d4+1 12 kh as the module does) and it outputs in the same way 3 elements: the result, a descriptive string and the internal datastructure.

    The following code is different from Games::Dice::Roller because it has less constraints in received inputs: for example it accepts something like 6d4r1kh3+3 and computes also a correct result, but messing the description. My mudule would reject an input like this.

    Possible inputs given as argument of the program:

    3d6 # simplest one 3d6+3 # with a result modifier 3d8r1 # reroll and discard any 1 3d8rlt3 # reroll and discard any lesser than 3 3d8rgt6 # reroll and discard any greater than 6 3d8rgt6+2 # reroll and discard any greater than 6 and add +2 to the f +inal result 4d6x1 # explode (a new roll is done) each 1 rolled 4d6xlt3 # explode lesser than 3 4d6xgt4 # explode greater than 4 4d12kh3 # keep highest 3 rolls 4d12kl3 # keep lowest 3 rolls 4d12dh3 # drop highest 3 rolls 4d12dl3 # drop lowest 3 rolls 4d20kh3+7 # keep hishets 3 rolls then add 7

    Alea iacta est!

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
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 browsing the Monastery: (6)
As of 2021-01-17 03:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?